Fix list index out of bounds crash on loading of .pls playlists, thanks to Tim Beaule...
[amarok.git] / src / amarok.h
blobb7527c42534881c447bb63d5df2a5bd104641126
1 //See COPYING file for licensing information
3 #ifndef AMAROK_H
4 #define AMAROK_H
6 #include <KActionCollection>
7 #include <KConfig>
8 #include <KIO/NetAccess>
9 #include <KUrl> // recursiveUrlExpand
11 #include "amarok_export.h"
13 class QColor;
14 class QDateTime;
15 class QEvent;
16 class QMutex;
17 class QPixmap;
18 class QWidget;
19 class Q3ListView;
20 class Q3ListViewItem;
21 namespace KIO { class Job; }
23 namespace Amarok
25 const int VOLUME_MAX = 100;
26 const int SCOPE_SIZE = 9; //= 2**9 = 512
27 const int blue = 0x202050;
28 const int VOLUME_SENSITIVITY = 30; //for mouse wheels
29 const int GUI_THREAD_ID = 0;
31 extern QMutex globalDirsMutex; // defined in app.cpp
33 namespace ColorScheme
35 ///eg. base of the Amarok Player-window
36 extern QColor Base; //Amarok::blue
37 ///eg. text in the Amarok Player-window
38 extern QColor Text; //Qt::white
39 ///eg. background colour for Amarok::PrettySliders
40 extern QColor Background; //brighter blue
41 ///eg. outline of slider widgets in Player-window
42 extern QColor Foreground; //lighter blue
43 ///eg. K3ListView alternative row color
44 extern QColor AltBase; //grey toned base
47 /** The version of the playlist XML format. Increase whenever it changes backwards-incompatibly. */
48 inline QString xmlVersion() { return "2.4"; }
50 /**
51 * Convenience function to return the KApplication instance KConfig object
52 * pre-set to a specific group.
53 * @param group Will pre-set the KConfig object to this group.
55 /* FIXME: This function can lead to very bizarre and hard to figure bugs.
56 While we don`t fix it properly, use it like this: amarok::config( Group )->readEntry( ... ) */
57 AMAROK_EXPORT KConfigGroup config( const QString &group = "General" ); //defined in app.cpp
59 /**
60 * @return the KActionCollection used by Amarok
61 * The KActionCollection is owned by the PlaylistWindow, so you must ensure
62 * you don't try to use this before then, but we've taken steps to prevent
63 * this eventuality - you should be safe.
65 KActionCollection *actionCollection(); //defined in app.cpp
67 /**
68 * Invoke the external web browser set in Amarok's configuration.
69 * @param url The URL to be opened in the browser.
70 * @return True if the browser could be started.
72 bool invokeBrowser( const QString& url ); //defined in app.cpp
74 /**
75 * The mainWindow is the playlistWindow
77 AMAROK_EXPORT QWidget *mainWindow(); //defined in app.cpp
79 /**
80 * Allocate one on the stack, and it'll set the busy cursor for you until it
81 * is destroyed
83 class OverrideCursor { //defined in app.cpp
84 public:
85 OverrideCursor( Qt::CursorShape cursor = Qt::WaitCursor );
86 ~OverrideCursor();
89 /**
90 * For saving files to ~/.kde/share/apps/amarok/directory
91 * @param directory will be created if not existing, you MUST end the string
92 * with '/'
94 AMAROK_EXPORT QString saveLocation( const QString &directory = QString() ); //defined in collectionreader.cpp
96 KIO::Job *trashFiles( const KUrl::List &files ); //defined in app.cpp
98 /**
99 * For recursively expanding the contents of a directory into a KUrl::List
100 * (playlists are ignored)
102 //PORT 2.0
103 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl &url, int maxURLs = -1 ); //defined in playlistloader.cpp
104 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl::List &urls, int maxURLs = -1 ); //defined in playlistloader.cpp
106 //New in Amarok2 -> recursiveUrlExpand has been replaced
107 //existing code depending on this port need to be changed (max urls is removed)
108 AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl &url ); //defined in PlaylistHandler.cpp
109 AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl::List &urls ); //defined in PlaylistHandler.cpp
111 AMAROK_EXPORT QString verboseTimeSince( const QDateTime &datetime ); //defined in tracktooltip.cpp
113 AMAROK_EXPORT QString verboseTimeSince( uint time_t ); //defined in tracktooltip.cpp
116 * Function that must be used when separating contextBrowser escaped urls
118 // defined in Statistics.cpp
119 void albumArtistTrackFromUrl( QString url, QString &artist, QString &album, QString &detail );
122 * @return the LOWERCASE file extension without the preceding '.', or "" if there is none
124 inline QString extension( const QString &fileName )
126 return fileName.contains( '.' ) ? fileName.mid( fileName.lastIndexOf( '.' ) + 1 ).toLower() : "";
129 /** Transform url into a file url if possible */
130 inline KUrl mostLocalURL( const KUrl &url )
132 return KIO::NetAccess::mostLocalUrl( url, mainWindow() );
136 * @return the last directory in @param fileName
138 inline QString directory( const QString &fileName )
140 return fileName.section( '/', 0, -2 );
144 * Returns internal code for database type, DbConnection::sqlite, DbConnection::mysql, or DbConnection::postgresql
145 * @param type either "SQLite", "MySQL", or "Postgresql".
147 int databaseTypeCode( const QString type ); //defined in configdialog.cpp
149 void setUseScores( bool use ); //defined in app.cpp
150 void setUseRatings( bool use );
151 void setMoodbarPrefs( bool show, bool moodier, int alter, bool withMusic );
153 bool repeatNone(); //defined in actionclasses.cpp
154 bool repeatTrack();
155 bool repeatAlbum();
156 bool repeatPlaylist();
157 bool randomOff();
158 bool randomTracks();
159 bool randomAlbums();
160 bool favorNone();
161 bool favorScores();
162 bool favorRatings();
163 bool favorLastPlay();
164 bool entireAlbums(); //repeatAlbum() || randomAlbums()
166 // Port 2.0: Reenable when we have a new dynamic mode
167 // const DynamicMode *dynamicMode(); //defined in playlist.cpp
169 QStringList splitPath( QString path ); //defined in playlistbrowser.cpp
172 * Maps the icon name to a system icon or custom Amarok icon, depending on the settings.
174 AMAROK_EXPORT QString icon( const QString& name ); //defined in iconloader.cpp
177 * Removes accents from the string
178 * @param path The original path.
179 * @return The cleaned up path.
181 AMAROK_EXPORT QString cleanPath( const QString &path ); //defined in app.cpp
184 * Replaces all non-ASCII characters with '_'.
185 * @param path The original path.
186 * @return The ASCIIfied path.
188 AMAROK_EXPORT QString asciiPath( const QString &path ); //defined in app.cpp
191 * Transform path into one valid on VFAT file systems
192 * @param path The original path.
193 * @return The cleaned up path.
195 AMAROK_EXPORT QString vfatPath( const QString &path ); //defined in app.cpp
198 * Compare both strings from left to right and remove the common part from input
199 * @param input the string that get's cleaned.
200 * @param ref a reference to compare input with.
201 * @return The cleaned up string.
203 AMAROK_EXPORT QString decapitateString( const QString &input, const QString &ref );
206 * Transform to be usable within HTML/HTML attributes
208 AMAROK_EXPORT QString escapeHTMLAttr( const QString &s );
209 AMAROK_EXPORT QString unescapeHTMLAttr( const QString &s ); //defined in statistics.cpp
211 /* defined in scriptmanager.cpp */
213 * Returns the proxy that should be used for a given URL.
214 * @param url the url.
215 * @return The url of the proxy, or a empty string if no proxy should be used.
217 QString proxyForUrl(const QString& url);
220 * Returns the proxy that should be used for a given protocol.
221 * @param protocol the protocol.
222 * @return The url of the proxy, or a empty string if no proxy should be used.
224 QString proxyForProtocol(const QString& protocol);
226 /*defined in collectionbrowser/collectiontreeitemmodel.cpp */
228 * Small function aimed to convert Eagles, The -> The Eagles (and back again).
229 * @param str the string to manipulate
230 * @param reverse if true, The Eagles -> Eagles, The. If false, Eagles, The -> The Eagles
232 AMAROK_EXPORT void manipulateThe( QString &str, bool reverse );
237 * Use this to const-iterate over QStringLists, if you like.
238 * Watch out for the definition of last in the scope of your for.
240 * QStringList strings;
241 * oldForeach( strings )
242 * debug() << *it << endl;
244 #define oldForeach( x ) \
245 for( QStringList::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
248 * You can use this for lists that aren't QStringLists.
249 * Watch out for the definition of last in the scope of your for.
251 * BundleList bundles;
252 * oldForeachType( BundleList, bundles )
253 * debug() << *it.url() << endl;
255 #define oldForeachType( Type, x ) \
256 for( Type::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
259 * Creates iterators of type @p Type.
260 * Watch out for the definitions of last and end in your scope.
262 * BundleList bundles;
263 * for( for_iterators( BundleList, bundles ); it != end; ++it )
264 * debug() << *it.url() << endl;
266 #define for_iterators( Type, x ) \
267 Type::ConstIterator it = x.begin(), end = x.end(), last = x.fromLast()
270 /// Update this when necessary
271 #define APP_VERSION "2.0-SVN"
273 #endif