add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / amarok.h
blob5a2e2fcb7c413a4e33ee2ce89fd3c5c224f719e6
1 //See COPYING file for licensing information
3 #ifndef AMAROK_H
4 #define AMAROK_H
6 #include <K3ProcIO> //Amarok::ProcIO
7 #include <KActionCollection>
8 #include <KConfig>
9 #include <KIO/NetAccess>
10 #include <KUrl> // recursiveUrlExpand
12 #include "amarok_export.h"
14 class QColor;
15 class QDateTime;
16 class QEvent;
17 class QMutex;
18 class QPixmap;
19 class QWidget;
20 class Q3ListView;
21 class Q3ListViewItem;
22 namespace KIO { class Job; }
24 namespace Amarok
26 const int VOLUME_MAX = 100;
27 const int SCOPE_SIZE = 9; //= 2**9 = 512
28 const int blue = 0x202050;
29 const int VOLUME_SENSITIVITY = 30; //for mouse wheels
30 const int GUI_THREAD_ID = 0;
32 extern QMutex globalDirsMutex; // defined in app.cpp
34 namespace ColorScheme
36 ///eg. base of the Amarok Player-window
37 extern QColor Base; //Amarok::blue
38 ///eg. text in the Amarok Player-window
39 extern QColor Text; //Qt::white
40 ///eg. background colour for Amarok::PrettySliders
41 extern QColor Background; //brighter blue
42 ///eg. outline of slider widgets in Player-window
43 extern QColor Foreground; //lighter blue
44 ///eg. K3ListView alternative row color
45 extern QColor AltBase; //grey toned base
48 /** The version of the playlist XML format. Increase whenever it changes backwards-incompatibly. */
49 inline QString xmlVersion() { return "2.4"; }
51 /**
52 * Convenience function to return the KApplication instance KConfig object
53 * pre-set to a specific group.
54 * @param group Will pre-set the KConfig object to this group.
56 /* FIXME: This function can lead to very bizarre and hard to figure bugs.
57 While we don`t fix it properly, use it like this: amarok::config( Group )->readEntry( ... ) */
58 AMAROK_EXPORT KConfigGroup config( const QString &group = "General" ); //defined in app.cpp
60 /**
61 * @return the KActionCollection used by Amarok
62 * The KActionCollection is owned by the PlaylistWindow, so you must ensure
63 * you don't try to use this before then, but we've taken steps to prevent
64 * this eventuality - you should be safe.
66 KActionCollection *actionCollection(); //defined in app.cpp
68 /**
69 * An event handler that handles events in a generic Amarok fashion. Mainly
70 * useful for drops, ie offers the Amarok popup for adding tracks to the
71 * playlist. You shouldn't pass every event here, ie closeEvents will not be
72 * handled as expected! Check the source in app.cpp if you want to see what
73 * it can do.
74 * @param recipient The object that received the event.
75 * @param e The event you want handled in a generic fashion.
76 * @return true if the event was handled.
78 bool genericEventHandler( QWidget *recipient, QEvent *e ); //defined in app.cpp
80 /**
81 * Invoke the external web browser set in Amarok's configuration.
82 * @param url The URL to be opened in the browser.
83 * @return True if the browser could be started.
85 bool invokeBrowser( const QString& url ); //defined in app.cpp
87 /**
88 * The mainWindow is the playlistWindow
90 AMAROK_EXPORT QWidget *mainWindow(); //defined in app.cpp
92 /**
93 * Allocate one on the stack, and it'll set the busy cursor for you until it
94 * is destroyed
96 class OverrideCursor { //defined in app.cpp
97 public:
98 OverrideCursor( Qt::CursorShape cursor = Qt::WaitCursor );
99 ~OverrideCursor();
103 * For saving files to ~/.kde/share/apps/amarok/directory
104 * @param directory will be created if not existing, you MUST end the string
105 * with '/'
107 AMAROK_EXPORT QString saveLocation( const QString &directory = QString() ); //defined in collectionreader.cpp
109 KIO::Job *trashFiles( const KUrl::List &files ); //defined in app.cpp
112 * For recursively expanding the contents of a directory into a KUrl::List
113 * (playlists are ignored)
115 //PORT 2.0
116 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl &url, int maxURLs = -1 ); //defined in playlistloader.cpp
117 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl::List &urls, int maxURLs = -1 ); //defined in playlistloader.cpp
119 QString verboseTimeSince( const QDateTime &datetime ); //defined in tracktooltip.cpp
121 QString verboseTimeSince( uint time_t ); //defined in tracktooltip.cpp
124 * Function that must be used when separating contextBrowser escaped urls
126 // defined in Statistics.cpp
127 void albumArtistTrackFromUrl( QString url, QString &artist, QString &album, QString &detail );
130 * @return the LOWERCASE file extension without the preceding '.', or "" if there is none
132 inline QString extension( const QString &fileName )
134 return fileName.contains( '.' ) ? fileName.mid( fileName.lastIndexOf( '.' ) + 1 ).toLower() : "";
137 /** Transform url into a file url if possible */
138 inline KUrl mostLocalURL( const KUrl &url )
140 return KIO::NetAccess::mostLocalUrl( url, mainWindow() );
144 * @return the last directory in @param fileName
146 inline QString directory( const QString &fileName )
148 return fileName.section( '/', 0, -2 );
150 /** Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
151 * Used by Amarok::ProcIO and Amarok::Process, exploiting commSetupDoneC(), a virtual method that
152 * happens to be called in the forked process
153 * See bug #103750 for more information.
155 //TODO ugly hack, fix K3Process for KDE 4.0
156 void closeOpenFiles(int out, int in, int err); //defined in scriptmanager.cpp
159 * Returns internal code for database type, DbConnection::sqlite, DbConnection::mysql, or DbConnection::postgresql
160 * @param type either "SQLite", "MySQL", or "Postgresql".
162 int databaseTypeCode( const QString type ); //defined in configdialog.cpp
164 void setUseScores( bool use ); //defined in app.cpp
165 void setUseRatings( bool use );
166 void setMoodbarPrefs( bool show, bool moodier, int alter, bool withMusic );
168 bool repeatNone(); //defined in actionclasses.cpp
169 bool repeatTrack();
170 bool repeatAlbum();
171 bool repeatPlaylist();
172 bool randomOff();
173 bool randomTracks();
174 bool randomAlbums();
175 bool favorNone();
176 bool favorScores();
177 bool favorRatings();
178 bool favorLastPlay();
179 bool entireAlbums(); //repeatAlbum() || randomAlbums()
181 // Port 2.0: Reenable when we have a new dynamic mode
182 // const DynamicMode *dynamicMode(); //defined in playlist.cpp
184 QStringList splitPath( QString path ); //defined in playlistbrowser.cpp
187 * Maps the icon name to a system icon or custom Amarok icon, depending on the settings.
189 AMAROK_EXPORT QString icon( const QString& name ); //defined in iconloader.cpp
192 * Removes accents from the string
193 * @param path The original path.
194 * @return The cleaned up path.
196 AMAROK_EXPORT QString cleanPath( const QString &path ); //defined in app.cpp
199 * Replaces all non-ASCII characters with '_'.
200 * @param path The original path.
201 * @return The ASCIIfied path.
203 AMAROK_EXPORT QString asciiPath( const QString &path ); //defined in app.cpp
206 * Transform path into one valid on VFAT file systems
207 * @param path The original path.
208 * @return The cleaned up path.
210 AMAROK_EXPORT QString vfatPath( const QString &path ); //defined in app.cpp
213 * Compare both strings from left to right and remove the common part from input
214 * @param input the string that get's cleaned.
215 * @param ref a reference to compare input with.
216 * @return The cleaned up string.
218 AMAROK_EXPORT QString decapitateString( const QString &input, const QString &ref );
221 * Transform to be usable within HTML/HTML attributes
223 AMAROK_EXPORT QString escapeHTMLAttr( const QString &s );
224 AMAROK_EXPORT QString unescapeHTMLAttr( const QString &s ); //defined in statistics.cpp
226 /* defined in scriptmanager.cpp */
228 * Returns the proxy that should be used for a given URL.
229 * @param url the url.
230 * @return The url of the proxy, or a empty string if no proxy should be used.
232 QString proxyForUrl(const QString& url);
235 * Returns the proxy that should be used for a given protocol.
236 * @param protocol the protocol.
237 * @return The url of the proxy, or a empty string if no proxy should be used.
239 QString proxyForProtocol(const QString& protocol);
241 /*defined in collectionbrowser/collectiontreeitemmodel.cpp */
243 * Small function aimed to convert Eagles, The -> The Eagles (and back again).
244 * @param str the string to manipulate
245 * @param reverse if true, The Eagles -> Eagles, The. If false, Eagles, The -> The Eagles
247 AMAROK_EXPORT void manipulateThe( QString &str, bool reverse );
249 ////////////////////////////////////////////////////////////////////////////////
250 // class Amarok::ProcIO
251 ////////////////////////////////////////////////////////////////////////////////
253 * Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
254 * Used by Amarok::ProcIO and AmarokProcess, exploiting commSetupDoneC(), a virtual method that
255 * happens to be called in the forked process
256 * See bug #103750 for more information.
258 class AMAROK_EXPORT ProcIO : public K3ProcIO {
259 public:
260 ProcIO(); // ctor sets the textcodec to UTF-8, in scriptmanager.cpp
261 virtual int commSetupDoneC() {
262 const int i = K3ProcIO::commSetupDoneC();
263 Amarok::closeOpenFiles( K3ProcIO::out[0],K3ProcIO::in[0],K3ProcIO::err[0] );
264 return i;
268 ////////////////////////////////////////////////////////////////////////////////
269 // class Amarok::Process
270 ////////////////////////////////////////////////////////////////////////////////
271 /** Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
272 * Used by Amarok::ProcIO and Amarok::Process, exploiting commSetupDoneC(), a virtual method that
273 * happens to be called in the forked process
274 * See bug #103750 for more information.
276 class AMAROK_EXPORT Process : public K3Process {
277 public:
278 Process( QObject *parent = 0 ) : K3Process( parent ) {}
279 virtual int commSetupDoneC() {
280 const int i = K3Process::commSetupDoneC();
281 Amarok::closeOpenFiles(K3Process::out[0],K3Process::in[0], K3Process::err[0]);
282 return i;
291 * Use this to const-iterate over QStringLists, if you like.
292 * Watch out for the definition of last in the scope of your for.
294 * QStringList strings;
295 * oldForeach( strings )
296 * debug() << *it << endl;
298 #define oldForeach( x ) \
299 for( QStringList::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
302 * You can use this for lists that aren't QStringLists.
303 * Watch out for the definition of last in the scope of your for.
305 * BundleList bundles;
306 * oldForeachType( BundleList, bundles )
307 * debug() << *it.url() << endl;
309 #define oldForeachType( Type, x ) \
310 for( Type::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
313 * Creates iterators of type @p Type.
314 * Watch out for the definitions of last and end in your scope.
316 * BundleList bundles;
317 * for( for_iterators( BundleList, bundles ); it != end; ++it )
318 * debug() << *it.url() << endl;
320 #define for_iterators( Type, x ) \
321 Type::ConstIterator it = x.begin(), end = x.end(), last = x.fromLast()
324 /// Update this when necessary
325 #define APP_VERSION "2.0-SVN"
327 #endif