1 //See COPYING file for licensing information
6 #include <K3ProcIO> //Amarok::ProcIO
7 #include <KActionCollection>
9 #include <KIO/NetAccess>
10 #include <KUrl> // recursiveUrlExpand
12 #include "amarok_export.h"
23 namespace KIO
{ class Job
; }
27 const int VOLUME_MAX
= 100;
28 const int SCOPE_SIZE
= 9; //= 2**9 = 512
29 const int blue
= 0x202050;
30 const int VOLUME_SENSITIVITY
= 30; //for mouse wheels
31 const int GUI_THREAD_ID
= 0;
33 extern QMutex globalDirsMutex
; // defined in app.cpp
37 ///eg. base of the Amarok Player-window
38 extern QColor Base
; //Amarok::blue
39 ///eg. text in the Amarok Player-window
40 extern QColor Text
; //Qt::white
41 ///eg. background colour for Amarok::PrettySliders
42 extern QColor Background
; //brighter blue
43 ///eg. outline of slider widgets in Player-window
44 extern QColor Foreground
; //lighter blue
45 ///eg. K3ListView alternative row color
46 extern QColor AltBase
; //grey toned base
49 /** The version of the playlist XML format. Increase whenever it changes backwards-incompatibly. */
50 inline QString
xmlVersion() { return "2.4"; }
53 * Convenience function to return the KApplication instance KConfig object
54 * pre-set to a specific group.
55 * @param group Will pre-set the KConfig object to this group.
57 /* FIXME: This function can lead to very bizarre and hard to figure bugs.
58 While we don`t fix it properly, use it like this: amarok::config( Group )->readEntry( ... ) */
59 AMAROK_EXPORT KConfigGroup
config( const QString
&group
= "General" ); //defined in app.cpp
62 * @return the KActionCollection used by Amarok
63 * The KActionCollection is owned by the PlaylistWindow, so you must ensure
64 * you don't try to use this before then, but we've taken steps to prevent
65 * this eventuality - you should be safe.
67 KActionCollection
*actionCollection(); //defined in app.cpp
70 * An event handler that handles events in a generic Amarok fashion. Mainly
71 * useful for drops, ie offers the Amarok popup for adding tracks to the
72 * playlist. You shouldn't pass every event here, ie closeEvents will not be
73 * handled as expected! Check the source in app.cpp if you want to see what
75 * @param recipient The object that received the event.
76 * @param e The event you want handled in a generic fashion.
77 * @return true if the event was handled.
79 bool genericEventHandler( QWidget
*recipient
, QEvent
*e
); //defined in app.cpp
82 * Invoke the external web browser set in Amarok's configuration.
83 * @param url The URL to be opened in the browser.
84 * @return True if the browser could be started.
86 bool invokeBrowser( const QString
& url
); //defined in app.cpp
89 * Obtain an Amarok PNG image as a QPixmap
91 QPixmap
getPNG( const QString
& /*fileName*/ ); //defined in app.cpp
94 * Obtain an Amarok JPG image as a QPixmap
96 QPixmap
getJPG( const QString
& /*fileName*/ ); //defined in app.cpp
99 * The mainWindow is the playlistWindow
101 QWidget
*mainWindow(); //defined in app.cpp
104 * Allocate one on the stack, and it'll set the busy cursor for you until it
107 class OverrideCursor
{ //defined in app.cpp
109 OverrideCursor( Qt::CursorShape cursor
= Qt::WaitCursor
);
114 * For saving files to ~/.kde/share/apps/amarok/directory
115 * @param directory will be created if not existing, you MUST end the string
118 AMAROK_EXPORT QString
saveLocation( const QString
&directory
= QString() ); //defined in collectionreader.cpp
120 KIO::Job
*trashFiles( const KUrl::List
&files
); //defined in app.cpp
123 * For recursively expanding the contents of a directory into a KUrl::List
124 * (playlists are ignored)
127 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl &url, int maxURLs = -1 ); //defined in playlistloader.cpp
128 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl::List &urls, int maxURLs = -1 ); //defined in playlistloader.cpp
130 QString
verboseTimeSince( const QDateTime
&datetime
); //defined in contextbrowser.cpp
132 QString
verboseTimeSince( uint
time_t ); //defined in contextbrowser.cpp
135 * Function that must be used when separating contextBrowser escaped urls
137 // defined in contextbrowser.cpp
138 void albumArtistTrackFromUrl( QString url
, QString
&artist
, QString
&album
, QString
&detail
);
141 * @return the LOWERCASE file extension without the preceding '.', or "" if there is none
143 inline QString
extension( const QString
&fileName
)
145 return fileName
.contains( '.' ) ? fileName
.mid( fileName
.lastIndexOf( '.' ) + 1 ).toLower() : "";
148 /** Transform url into a file url if possible */
149 inline KUrl
mostLocalURL( const KUrl
&url
)
151 return KIO::NetAccess::mostLocalUrl( url
, mainWindow() );
155 * @return the last directory in @param fileName
157 inline QString
directory( const QString
&fileName
)
159 return fileName
.section( '/', 0, -2 );
161 /** Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
162 * Used by Amarok::ProcIO and Amarok::Process, exploiting commSetupDoneC(), a virtual method that
163 * happens to be called in the forked process
164 * See bug #103750 for more information.
166 //TODO ugly hack, fix K3Process for KDE 4.0
167 void closeOpenFiles(int out
, int in
, int err
); //defined in scriptmanager.cpp
170 * Returns internal code for database type, DbConnection::sqlite, DbConnection::mysql, or DbConnection::postgresql
171 * @param type either "SQLite", "MySQL", or "Postgresql".
173 int databaseTypeCode( const QString type
); //defined in configdialog.cpp
175 void setUseScores( bool use
); //defined in app.cpp
176 void setUseRatings( bool use
);
177 void setMoodbarPrefs( bool show
, bool moodier
, int alter
, bool withMusic
);
179 bool repeatNone(); //defined in actionclasses.cpp
182 bool repeatPlaylist();
189 bool favorLastPlay();
190 bool entireAlbums(); //repeatAlbum() || randomAlbums()
192 const DynamicMode
*dynamicMode(); //defined in playlist.cpp
194 Q3ListViewItem
* findItemByPath( Q3ListView
*view
, QString path
); //defined in playlistbrowser.cpp
195 QStringList
splitPath( QString path
); //defined in playlistbrowser.cpp
198 * Maps the icon name to a system icon or custom Amarok icon, depending on the settings.
200 AMAROK_EXPORT QString
icon( const QString
& name
); //defined in iconloader.cpp
203 * Removes accents from the string
204 * @param path The original path.
205 * @return The cleaned up path.
207 AMAROK_EXPORT QString
cleanPath( const QString
&path
); //defined in app.cpp
210 * Replaces all non-ASCII characters with '_'.
211 * @param path The original path.
212 * @return The ASCIIfied path.
214 AMAROK_EXPORT QString
asciiPath( const QString
&path
); //defined in app.cpp
217 * Transform path into one valid on VFAT file systems
218 * @param path The original path.
219 * @return The cleaned up path.
221 AMAROK_EXPORT QString
vfatPath( const QString
&path
); //defined in app.cpp
224 * Compare both strings from left to right and remove the common part from input
225 * @param input the string that get's cleaned.
226 * @param ref a reference to compare input with.
227 * @return The cleaned up string.
229 AMAROK_EXPORT QString
decapitateString( const QString
&input
, const QString
&ref
);
232 * Transform to be usable within HTML/HTML attributes
234 AMAROK_EXPORT QString
escapeHTMLAttr( const QString
&s
);
235 AMAROK_EXPORT QString
unescapeHTMLAttr( const QString
&s
); //defined in statistics.cpp
237 /* defined in scriptmanager.cpp */
239 * Returns the proxy that should be used for a given URL.
240 * @param url the url.
241 * @return The url of the proxy, or a empty string if no proxy should be used.
243 QString
proxyForUrl(const QString
& url
);
246 * Returns the proxy that should be used for a given protocol.
247 * @param protocol the protocol.
248 * @return The url of the proxy, or a empty string if no proxy should be used.
250 QString
proxyForProtocol(const QString
& protocol
);
252 /*defined in collectionbrowser/collectiontreeitemmodel.cpp */
254 * Small function aimed to convert Eagles, The -> The Eagles (and back again).
255 * @param str the string to manipulate
256 * @param reverse if true, The Eagles -> Eagles, The. If false, Eagles, The -> The Eagles
258 void manipulateThe( QString
&str
, bool reverse
);
260 ////////////////////////////////////////////////////////////////////////////////
261 // class Amarok::ProcIO
262 ////////////////////////////////////////////////////////////////////////////////
264 * Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
265 * Used by Amarok::ProcIO and AmarokProcess, exploiting commSetupDoneC(), a virtual method that
266 * happens to be called in the forked process
267 * See bug #103750 for more information.
269 class AMAROK_EXPORT ProcIO
: public K3ProcIO
{
271 ProcIO(); // ctor sets the textcodec to UTF-8, in scriptmanager.cpp
272 virtual int commSetupDoneC() {
273 const int i
= K3ProcIO::commSetupDoneC();
274 Amarok::closeOpenFiles( K3ProcIO::out
[0],K3ProcIO::in
[0],K3ProcIO::err
[0] );
279 ////////////////////////////////////////////////////////////////////////////////
280 // class Amarok::Process
281 ////////////////////////////////////////////////////////////////////////////////
282 /** Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
283 * Used by Amarok::ProcIO and Amarok::Process, exploiting commSetupDoneC(), a virtual method that
284 * happens to be called in the forked process
285 * See bug #103750 for more information.
287 class AMAROK_EXPORT Process
: public K3Process
{
289 Process( QObject
*parent
= 0 ) : K3Process( parent
) {}
290 virtual int commSetupDoneC() {
291 const int i
= K3Process::commSetupDoneC();
292 Amarok::closeOpenFiles(K3Process::out
[0],K3Process::in
[0], K3Process::err
[0]);
302 * Use this to const-iterate over QStringLists, if you like.
303 * Watch out for the definition of last in the scope of your for.
305 * QStringList strings;
306 * oldForeach( strings )
307 * debug() << *it << endl;
309 #define oldForeach( x ) \
310 for( QStringList::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
313 * You can use this for lists that aren't QStringLists.
314 * Watch out for the definition of last in the scope of your for.
316 * BundleList bundles;
317 * oldForeachType( BundleList, bundles )
318 * debug() << *it.url() << endl;
320 #define oldForeachType( Type, x ) \
321 for( Type::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
324 * Creates iterators of type @p Type.
325 * Watch out for the definitions of last and end in your scope.
327 * BundleList bundles;
328 * for( for_iterators( BundleList, bundles ); it != end; ++it )
329 * debug() << *it.url() << endl;
331 #define for_iterators( Type, x ) \
332 Type::ConstIterator it = x.begin(), end = x.end(), last = x.fromLast()
335 /// Update this when necessary
336 #define APP_VERSION "2.0-SVN"