1 //See COPYING file for licensing information
6 #include <qnamespace.h>
12 #include <kactioncollection.h>
14 #include <kurl.h> // recursiveUrlExpand
15 #include <k3procio.h> //Amarok::ProcIO
16 #include <kio/netaccess.h>
18 #include "amarok_export.h"
29 namespace KIO
{ class Job
; }
33 const int VOLUME_MAX
= 100;
34 const int SCOPE_SIZE
= 9; //= 2**9 = 512
35 const int blue
= 0x202050;
36 const int VOLUME_SENSITIVITY
= 30; //for mouse wheels
37 const int GUI_THREAD_ID
= 0;
39 extern QMutex globalDirsMutex
; // defined in app.cpp
43 ///eg. base of the Amarok Player-window
44 extern QColor Base
; //Amarok::blue
45 ///eg. text in the Amarok Player-window
46 extern QColor Text
; //Qt::white
47 ///eg. background colour for Amarok::PrettySliders
48 extern QColor Background
; //brighter blue
49 ///eg. outline of slider widgets in Player-window
50 extern QColor Foreground
; //lighter blue
51 ///eg. K3ListView alternative row color
52 extern QColor AltBase
; //grey toned base
55 /** The version of the playlist XML format. Increase whenever it changes backwards-incompatibly. */
56 inline QString
xmlVersion() { return "2.4"; }
59 * Convenience function to return the KApplication instance KConfig object
60 * pre-set to a specific group.
61 * @param group Will pre-set the KConfig object to this group.
63 /* FIXME: This function can lead to very bizarre and hard to figure bugs.
64 While we don`t fix it properly, use it like this: amarok::config( Group )->readEntry( ... ) */
65 KConfigGroup
config( const QString
&group
= "General" ); //defined in app.cpp
68 * @return the KActionCollection used by Amarok
69 * The KActionCollection is owned by the PlaylistWindow, so you must ensure
70 * you don't try to use this before then, but we've taken steps to prevent
71 * this eventuality - you should be safe.
73 KActionCollection
*actionCollection(); //defined in app.cpp
76 * An event handler that handles events in a generic Amarok fashion. Mainly
77 * useful for drops, ie offers the Amarok popup for adding tracks to the
78 * playlist. You shouldn't pass every event here, ie closeEvents will not be
79 * handled as expected! Check the source in app.cpp if you want to see what
81 * @param recipient The object that received the event.
82 * @param e The event you want handled in a generic fashion.
83 * @return true if the event was handled.
85 bool genericEventHandler( QWidget
*recipient
, QEvent
*e
); //defined in app.cpp
88 * Invoke the external web browser set in Amarok's configuration.
89 * @param url The URL to be opened in the browser.
90 * @return True if the browser could be started.
92 bool invokeBrowser( const QString
& url
); //defined in app.cpp
95 * Obtain an Amarok PNG image as a QPixmap
97 QPixmap
getPNG( const QString
& /*fileName*/ ); //defined in app.cpp
100 * Obtain an Amarok JPG image as a QPixmap
102 QPixmap
getJPG( const QString
& /*fileName*/ ); //defined in app.cpp
105 * The mainWindow is the playlistWindow
107 QWidget
*mainWindow(); //defined in app.cpp
110 * Allocate one on the stack, and it'll set the busy cursor for you until it
113 class OverrideCursor
{ //defined in app.cpp
115 OverrideCursor( Qt::CursorShape cursor
= Qt::WaitCursor
);
120 * For saving files to ~/.kde/share/apps/amarok/directory
121 * @param directory will be created if not existing, you MUST end the string
124 AMAROK_EXPORT QString
saveLocation( const QString
&directory
= QString() ); //defined in collectionreader.cpp
126 KIO::Job
*trashFiles( const KUrl::List
&files
); //defined in app.cpp
129 * For recursively expanding the contents of a directory into a KUrl::List
130 * (playlists are ignored)
132 AMAROK_EXPORT
KUrl::List
recursiveUrlExpand( const KUrl
&url
, int maxURLs
= -1 ); //defined in playlistloader.cpp
133 AMAROK_EXPORT
KUrl::List
recursiveUrlExpand( const KUrl::List
&urls
, int maxURLs
= -1 ); //defined in playlistloader.cpp
135 QString
verboseTimeSince( const QDateTime
&datetime
); //defined in contextbrowser.cpp
137 QString
verboseTimeSince( uint
time_t ); //defined in contextbrowser.cpp
140 * Function that must be used when separating contextBrowser escaped urls
142 // defined in contextbrowser.cpp
143 void albumArtistTrackFromUrl( QString url
, QString
&artist
, QString
&album
, QString
&detail
);
146 * @return the LOWERCASE file extension without the preceding '.', or "" if there is none
148 inline QString
extension( const QString
&fileName
)
150 return fileName
.contains( '.' ) ? fileName
.mid( fileName
.lastIndexOf( '.' ) + 1 ).toLower() : "";
153 /** Transform url into a file url if possible */
154 inline KUrl
mostLocalURL( const KUrl
&url
)
156 return KIO::NetAccess::mostLocalUrl( url
, mainWindow() );
160 * @return the last directory in @param fileName
162 inline QString
directory( const QString
&fileName
)
164 return fileName
.section( '/', 0, -2 );
166 /** Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
167 * Used by Amarok::ProcIO and Amarok::Process, exploiting commSetupDoneC(), a virtual method that
168 * happens to be called in the forked process
169 * See bug #103750 for more information.
171 //TODO ugly hack, fix K3Process for KDE 4.0
172 void closeOpenFiles(int out
, int in
, int err
); //defined in scriptmanager.cpp
175 * Returns internal code for database type, DbConnection::sqlite, DbConnection::mysql, or DbConnection::postgresql
176 * @param type either "SQLite", "MySQL", or "Postgresql".
178 int databaseTypeCode( const QString type
); //defined in configdialog.cpp
180 void setUseScores( bool use
); //defined in app.cpp
181 void setUseRatings( bool use
);
182 void setMoodbarPrefs( bool show
, bool moodier
, int alter
, bool withMusic
);
184 bool repeatNone(); //defined in actionclasses.cpp
187 bool repeatPlaylist();
194 bool favorLastPlay();
195 bool entireAlbums(); //repeatAlbum() || randomAlbums()
197 const DynamicMode
*dynamicMode(); //defined in playlist.cpp
199 Q3ListViewItem
* findItemByPath( Q3ListView
*view
, QString path
); //defined in playlistbrowser.cpp
200 QStringList
splitPath( QString path
); //defined in playlistbrowser.cpp
203 * Maps the icon name to a system icon or custom Amarok icon, depending on the settings.
205 AMAROK_EXPORT QString
icon( const QString
& name
); //defined in iconloader.cpp
208 * Removes accents from the string
209 * @param path The original path.
210 * @return The cleaned up path.
212 AMAROK_EXPORT QString
cleanPath( const QString
&path
); //defined in app.cpp
215 * Replaces all non-ASCII characters with '_'.
216 * @param path The original path.
217 * @return The ASCIIfied path.
219 AMAROK_EXPORT QString
asciiPath( const QString
&path
); //defined in app.cpp
222 * Transform path into one valid on VFAT file systems
223 * @param path The original path.
224 * @return The cleaned up path.
226 AMAROK_EXPORT QString
vfatPath( const QString
&path
); //defined in app.cpp
229 * Compare both strings from left to right and remove the common part from input
230 * @param input the string that get's cleaned.
231 * @param ref a reference to compare input with.
232 * @return The cleaned up string.
234 AMAROK_EXPORT QString
decapitateString( const QString
&input
, const QString
&ref
);
237 * Transform to be usable within HTML/HTML attributes
238 * defined in contextbrowser.cpp
240 AMAROK_EXPORT QString
escapeHTMLAttr( const QString
&s
);
241 AMAROK_EXPORT QString
unescapeHTMLAttr( const QString
&s
);
243 /* defined in scriptmanager.cpp */
245 * Returns the proxy that should be used for a given URL.
246 * @param url the url.
247 * @return The url of the proxy, or a empty string if no proxy should be used.
249 QString
proxyForUrl(const QString
& url
);
252 * Returns the proxy that should be used for a given protocol.
253 * @param protocol the protocol.
254 * @return The url of the proxy, or a empty string if no proxy should be used.
256 QString
proxyForProtocol(const QString
& protocol
);
258 ////////////////////////////////////////////////////////////////////////////////
259 // class Amarok::ProcIO
260 ////////////////////////////////////////////////////////////////////////////////
262 * Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
263 * Used by Amarok::ProcIO and AmarokProcess, exploiting commSetupDoneC(), a virtual method that
264 * happens to be called in the forked process
265 * See bug #103750 for more information.
267 class AMAROK_EXPORT ProcIO
: public K3ProcIO
{
269 ProcIO(); // ctor sets the textcodec to UTF-8, in scriptmanager.cpp
270 virtual int commSetupDoneC() {
271 const int i
= K3ProcIO::commSetupDoneC();
272 Amarok::closeOpenFiles( K3ProcIO::out
[0],K3ProcIO::in
[0],K3ProcIO::err
[0] );
277 ////////////////////////////////////////////////////////////////////////////////
278 // class Amarok::Process
279 ////////////////////////////////////////////////////////////////////////////////
280 /** Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
281 * Used by Amarok::ProcIO and Amarok::Process, exploiting commSetupDoneC(), a virtual method that
282 * happens to be called in the forked process
283 * See bug #103750 for more information.
285 class AMAROK_EXPORT Process
: public K3Process
{
287 Process( QObject
*parent
= 0 ) : K3Process( parent
) {}
288 virtual int commSetupDoneC() {
289 const int i
= K3Process::commSetupDoneC();
290 Amarok::closeOpenFiles(K3Process::out
[0],K3Process::in
[0], K3Process::err
[0]);
300 * Use this to const-iterate over QStringLists, if you like.
301 * Watch out for the definition of last in the scope of your for.
303 * QStringList strings;
304 * oldForeach( strings )
305 * debug() << *it << endl;
307 #define oldForeach( x ) \
308 for( QStringList::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
311 * You can use this for lists that aren't QStringLists.
312 * Watch out for the definition of last in the scope of your for.
314 * BundleList bundles;
315 * oldForeachType( BundleList, bundles )
316 * debug() << *it.url() << endl;
318 #define oldForeachType( Type, x ) \
319 for( Type::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
322 * Creates iterators of type @p Type.
323 * Watch out for the definitions of last and end in your scope.
325 * BundleList bundles;
326 * for( for_iterators( BundleList, bundles ); it != end; ++it )
327 * debug() << *it.url() << endl;
329 #define for_iterators( Type, x ) \
330 Type::ConstIterator it = x.begin(), end = x.end(), last = x.fromLast()
333 /// Update this when necessary
334 #define APP_VERSION "2.0-SVN"