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"
22 namespace KIO
{ class Job
; }
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
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"; }
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
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
69 * Invoke the external web browser set in Amarok's configuration.
70 * @param url The URL to be opened in the browser.
71 * @return True if the browser could be started.
73 bool invokeBrowser( const QString
& url
); //defined in app.cpp
76 * The mainWindow is the playlistWindow
78 AMAROK_EXPORT QWidget
*mainWindow(); //defined in app.cpp
81 * Allocate one on the stack, and it'll set the busy cursor for you until it
84 class OverrideCursor
{ //defined in app.cpp
86 OverrideCursor( Qt::CursorShape cursor
= Qt::WaitCursor
);
91 * For saving files to ~/.kde/share/apps/amarok/directory
92 * @param directory will be created if not existing, you MUST end the string
95 AMAROK_EXPORT QString
saveLocation( const QString
&directory
= QString() ); //defined in collectionreader.cpp
97 KIO::Job
*trashFiles( const KUrl::List
&files
); //defined in app.cpp
100 * For recursively expanding the contents of a directory into a KUrl::List
101 * (playlists are ignored)
104 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl &url, int maxURLs = -1 ); //defined in playlistloader.cpp
105 // AMAROK_EXPORT KUrl::List recursiveUrlExpand( const KUrl::List &urls, int maxURLs = -1 ); //defined in playlistloader.cpp
107 //New in Amarok2 -> recursiveUrlExpand has been replaced
108 //existing code depending on this port need to be changed (max urls is removed)
109 AMAROK_EXPORT
KUrl::List
recursiveUrlExpand( const KUrl
&url
); //defined in PlaylistHandler.cpp
110 AMAROK_EXPORT
KUrl::List
recursiveUrlExpand( const KUrl::List
&urls
); //defined in PlaylistHandler.cpp
112 AMAROK_EXPORT QString
verboseTimeSince( const QDateTime
&datetime
); //defined in tracktooltip.cpp
114 AMAROK_EXPORT QString
verboseTimeSince( uint
time_t ); //defined in tracktooltip.cpp
117 * Function that must be used when separating contextBrowser escaped urls
119 // defined in Statistics.cpp
120 void albumArtistTrackFromUrl( QString url
, QString
&artist
, QString
&album
, QString
&detail
);
123 * @return the LOWERCASE file extension without the preceding '.', or "" if there is none
125 inline QString
extension( const QString
&fileName
)
127 return fileName
.contains( '.' ) ? fileName
.mid( fileName
.lastIndexOf( '.' ) + 1 ).toLower() : "";
130 /** Transform url into a file url if possible */
131 inline KUrl
mostLocalURL( const KUrl
&url
)
133 return KIO::NetAccess::mostLocalUrl( url
, mainWindow() );
137 * @return the last directory in @param fileName
139 inline QString
directory( const QString
&fileName
)
141 return fileName
.section( '/', 0, -2 );
143 /** Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
144 * Used by Amarok::ProcIO and Amarok::Process, exploiting commSetupDoneC(), a virtual method that
145 * happens to be called in the forked process
146 * See bug #103750 for more information.
148 //TODO ugly hack, fix K3Process for KDE 4.0
149 void closeOpenFiles(int out
, int in
, int err
); //defined in scriptmanager.cpp
152 * Returns internal code for database type, DbConnection::sqlite, DbConnection::mysql, or DbConnection::postgresql
153 * @param type either "SQLite", "MySQL", or "Postgresql".
155 int databaseTypeCode( const QString type
); //defined in configdialog.cpp
157 void setUseScores( bool use
); //defined in app.cpp
158 void setUseRatings( bool use
);
159 void setMoodbarPrefs( bool show
, bool moodier
, int alter
, bool withMusic
);
161 bool repeatNone(); //defined in actionclasses.cpp
164 bool repeatPlaylist();
171 bool favorLastPlay();
172 bool entireAlbums(); //repeatAlbum() || randomAlbums()
174 // Port 2.0: Reenable when we have a new dynamic mode
175 // const DynamicMode *dynamicMode(); //defined in playlist.cpp
177 QStringList
splitPath( QString path
); //defined in playlistbrowser.cpp
180 * Maps the icon name to a system icon or custom Amarok icon, depending on the settings.
182 AMAROK_EXPORT QString
icon( const QString
& name
); //defined in iconloader.cpp
185 * Removes accents from the string
186 * @param path The original path.
187 * @return The cleaned up path.
189 AMAROK_EXPORT QString
cleanPath( const QString
&path
); //defined in app.cpp
192 * Replaces all non-ASCII characters with '_'.
193 * @param path The original path.
194 * @return The ASCIIfied path.
196 AMAROK_EXPORT QString
asciiPath( const QString
&path
); //defined in app.cpp
199 * Transform path into one valid on VFAT file systems
200 * @param path The original path.
201 * @return The cleaned up path.
203 AMAROK_EXPORT QString
vfatPath( const QString
&path
); //defined in app.cpp
206 * Compare both strings from left to right and remove the common part from input
207 * @param input the string that get's cleaned.
208 * @param ref a reference to compare input with.
209 * @return The cleaned up string.
211 AMAROK_EXPORT QString
decapitateString( const QString
&input
, const QString
&ref
);
214 * Transform to be usable within HTML/HTML attributes
216 AMAROK_EXPORT QString
escapeHTMLAttr( const QString
&s
);
217 AMAROK_EXPORT QString
unescapeHTMLAttr( const QString
&s
); //defined in statistics.cpp
219 /* defined in scriptmanager.cpp */
221 * Returns the proxy that should be used for a given URL.
222 * @param url the url.
223 * @return The url of the proxy, or a empty string if no proxy should be used.
225 QString
proxyForUrl(const QString
& url
);
228 * Returns the proxy that should be used for a given protocol.
229 * @param protocol the protocol.
230 * @return The url of the proxy, or a empty string if no proxy should be used.
232 QString
proxyForProtocol(const QString
& protocol
);
234 /*defined in collectionbrowser/collectiontreeitemmodel.cpp */
236 * Small function aimed to convert Eagles, The -> The Eagles (and back again).
237 * @param str the string to manipulate
238 * @param reverse if true, The Eagles -> Eagles, The. If false, Eagles, The -> The Eagles
240 AMAROK_EXPORT
void manipulateThe( QString
&str
, bool reverse
);
242 ////////////////////////////////////////////////////////////////////////////////
243 // class Amarok::ProcIO
244 ////////////////////////////////////////////////////////////////////////////////
246 * Due to xine-lib, we have to make K3Process close all fds, otherwise we get "device is busy" messages
247 * Used by Amarok::ProcIO and AmarokProcess, exploiting commSetupDoneC(), a virtual method that
248 * happens to be called in the forked process
249 * See bug #103750 for more information.
251 class AMAROK_EXPORT ProcIO
: public K3ProcIO
{
253 ProcIO(); // ctor sets the textcodec to UTF-8, in scriptmanager.cpp
254 virtual int commSetupDoneC() {
255 const int i
= K3ProcIO::commSetupDoneC();
256 Amarok::closeOpenFiles( K3ProcIO::out
[0],K3ProcIO::in
[0],K3ProcIO::err
[0] );
261 ////////////////////////////////////////////////////////////////////////////////
262 // class Amarok::Process
263 ////////////////////////////////////////////////////////////////////////////////
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 Amarok::Process, 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 Process
: public K3Process
{
271 Process( QObject
*parent
= 0 ) : K3Process( parent
) {}
272 virtual int commSetupDoneC() {
273 const int i
= K3Process::commSetupDoneC();
274 Amarok::closeOpenFiles(K3Process::out
[0],K3Process::in
[0], K3Process::err
[0]);
284 * Use this to const-iterate over QStringLists, if you like.
285 * Watch out for the definition of last in the scope of your for.
287 * QStringList strings;
288 * oldForeach( strings )
289 * debug() << *it << endl;
291 #define oldForeach( x ) \
292 for( QStringList::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
295 * You can use this for lists that aren't QStringLists.
296 * Watch out for the definition of last in the scope of your for.
298 * BundleList bundles;
299 * oldForeachType( BundleList, bundles )
300 * debug() << *it.url() << endl;
302 #define oldForeachType( Type, x ) \
303 for( Type::ConstIterator it = x.begin(), end = x.end(); it != end; ++it )
306 * Creates iterators of type @p Type.
307 * Watch out for the definitions of last and end in your scope.
309 * BundleList bundles;
310 * for( for_iterators( BundleList, bundles ); it != end; ++it )
311 * debug() << *it.url() << endl;
313 #define for_iterators( Type, x ) \
314 Type::ConstIterator it = x.begin(), end = x.end(), last = x.fromLast()
317 /// Update this when necessary
318 #define APP_VERSION "2.0-SVN"