Warning, file /multimedia/amarok/src/core/support/Amarok.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /**************************************************************************************** 0002 * Copyright (c) 2004-2005 Max Howell <max.howell@methylblue.com> * 0003 * Copyright (c) 2009 Mark Kretschmann <kretschmann@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #ifndef AMAROK_H 0019 #define AMAROK_H 0020 0021 #include "core/amarokcore_export.h" 0022 #include "Version.h" 0023 #include "core/meta/forward_declarations.h" 0024 0025 #include <KActionCollection> 0026 #include <KConfigGroup> 0027 0028 #include <QDir> 0029 #include <QPointer> 0030 0031 class QColor; 0032 class QDateTime; 0033 class QMutex; 0034 class QPixmap; 0035 0036 namespace KIO { class Job; } 0037 0038 namespace Amarok 0039 { 0040 const int VOLUME_MAX = 100; 0041 const int SCOPE_SIZE = 9; // = 2**9 = 512 0042 const int blue = 0x202050; 0043 const int VOLUME_SENSITIVITY = 30; // for mouse wheels 0044 const int GUI_THREAD_ID = 0; 0045 0046 extern QMutex globalDirsMutex; 0047 extern QPointer<KActionCollection> actionCollectionObject; 0048 0049 namespace ColorScheme 0050 { 0051 ///eg. base of the Amarok Player-window 0052 extern QColor Base; //Amarok::blue 0053 ///eg. text in the Amarok Player-window 0054 extern QColor Text; //Qt::white 0055 ///eg. background colour for Amarok::PrettySliders 0056 extern QColor Background; //brighter blue 0057 ///eg. outline of slider widgets in Player-window 0058 extern QColor Foreground; //lighter blue 0059 ///eg. K3ListView alternative row color 0060 extern QColor AltBase; //grey toned base 0061 } 0062 0063 /** The version of the playlist XML format. Increase whenever it changes backwards-incompatibly. */ 0064 inline QString xmlVersion() { return QStringLiteral("2.4"); } 0065 0066 /** 0067 * Convenience function to return the QApplication instance KConfig object 0068 * pre-set to a specific group. 0069 * @param group Will pre-set the KConfig object to this group. 0070 */ 0071 /* FIXME: This function can lead to very bizarre and hard to figure bugs. 0072 While we don`t fix it properly, use it like this: amarok::config( Group )->readEntry( ... ) */ 0073 AMAROKCORE_EXPORT KConfigGroup config( const QString &group = QStringLiteral("General") ); 0074 0075 /** 0076 * @return the KActionCollection used by Amarok 0077 */ 0078 AMAROKCORE_EXPORT KActionCollection *actionCollection(); 0079 0080 /** 0081 * Compute score for a track that has finished playing. 0082 * The resulting score is between 0 and 100 0083 */ 0084 inline double computeScore( double oldScore, unsigned int oldPlayCount, double playedFraction ) 0085 { 0086 const int percentage = qBound(0, int(playedFraction * 100), 100); 0087 double newScore; 0088 0089 if( oldPlayCount <= 0 ) 0090 newScore = ( oldScore + percentage ) / 2; 0091 else 0092 newScore = ( ( oldScore * oldPlayCount ) + percentage ) / ( oldPlayCount + 1 ); 0093 0094 return qBound( 0.0, newScore, 100.0 ); 0095 } 0096 0097 /** 0098 * Allocate one on the stack, and it'll set the busy cursor for you until it 0099 * is destroyed 0100 */ 0101 class OverrideCursor { 0102 public: 0103 explicit OverrideCursor( Qt::CursorShape cursor = Qt::WaitCursor ); 0104 ~OverrideCursor(); 0105 }; 0106 0107 /** 0108 * For saving files to ~/.local/share/amarok/ 0109 * @param directory: Subdirectory of ~/.local/share/amarok/ to save files to. 0110 */ 0111 AMAROKCORE_EXPORT QString saveLocation( const QString &directory = QString() ); 0112 0113 AMAROKCORE_EXPORT QString defaultPlaylistPath(); 0114 0115 AMAROKCORE_EXPORT QString verboseTimeSince( const QDateTime &datetime ); 0116 AMAROKCORE_EXPORT QString verboseTimeSince( uint time_t ); 0117 AMAROKCORE_EXPORT QString conciseTimeSince( uint time_t ); 0118 0119 /** 0120 * @return the LOWERCASE file extension without the preceding '.', or "" if there is none 0121 */ 0122 inline QString extension( const QString &fileName ) 0123 { 0124 if( fileName.contains( QLatin1Char('.') ) ) 0125 { 0126 QString ext = fileName.mid( fileName.lastIndexOf( QLatin1Char('.') ) + 1 ).toLower(); 0127 // Remove url parameters (some remote playlists use these) 0128 if( ext.contains( QLatin1Char('?') ) ) 0129 return ext.left( ext.indexOf( QLatin1Char('?') ) ); 0130 return ext; 0131 } 0132 0133 return QString(); 0134 } 0135 0136 void setUseScores( bool use ); 0137 void setUseRatings( bool use ); 0138 0139 bool repeatNone(); // defined in ActionClasses.cpp 0140 bool repeatTrack(); 0141 bool repeatAlbum(); 0142 bool repeatPlaylist(); 0143 bool randomOff(); 0144 bool randomTracks(); 0145 bool randomAlbums(); 0146 bool repeatEnabled(); 0147 bool randomEnabled(); 0148 bool favorNone(); 0149 bool favorScores(); 0150 bool favorRatings(); 0151 bool favorLastPlay(); 0152 0153 /** 0154 * Removes accents from the string 0155 * @param path The original path. 0156 * @return The cleaned up path. 0157 */ 0158 AMAROKCORE_EXPORT QString cleanPath( const QString &path ); 0159 0160 /** 0161 * Replaces all non-ASCII characters with '_'. 0162 * @param path The original path. 0163 * @return The ASCIIfied path. 0164 */ 0165 AMAROKCORE_EXPORT QString asciiPath( const QString &path ); 0166 0167 /** 0168 * Define how Amarok::vfatPath() should behave wrt path separators: 0169 * 0170 * AutoBehaviour: use WindowsBehaviour when compiled in Windows and UnixBehaviour 0171 * on everything else 0172 * UnixBehaviour: treat / as path separator and \ as a valid part of file name 0173 * WindowsBehaviour: treat \ as path separator and / as a valid part of file name 0174 */ 0175 enum PathSeparatorBehaviour 0176 { 0177 AutoBehaviour, 0178 UnixBehaviour, 0179 WindowsBehaviour 0180 }; 0181 0182 /** 0183 * Transforms path into one valid on VFAT file systems, leaves QDir::separator()s untouched. 0184 * Beware: Truncates path to 255 characters! 0185 * Replacement rules: illegal characters are being replaced by '_' 0186 * reserved device names are being prefixed with '_' 0187 * for file/folder names or extensions that end with a space it will be replaced by '_' 0188 * @param path The original path. 0189 * @param behaviour see PathSeparatorBehaviour. 0190 * @return The cleaned up path. 0191 */ 0192 AMAROKCORE_EXPORT QString vfatPath( const QString &path, 0193 PathSeparatorBehaviour behaviour = AutoBehaviour ); 0194 0195 /* defined in browsers/CollectionTreeItemModel.cpp */ 0196 /** 0197 * Small function aimed to convert Eagles, The -> The Eagles (and back again). 0198 * If there is no "the" in the name then the string is not changed. 0199 * @param str the string to manipulate 0200 * @param reverse if true, The Eagles -> Eagles, The. If false, Eagles, The -> The Eagles 0201 */ 0202 AMAROKCORE_EXPORT void manipulateThe( QString &str, bool reverse ); 0203 0204 /** 0205 * Return a playlist name based on the artist and album info of the tracks or a string 0206 * containing the creation date. 0207 */ 0208 AMAROKCORE_EXPORT QString generatePlaylistName( const Meta::TrackList &tracks ); 0209 0210 /** 0211 * Creates a semi-transparent Amarok logo for suitable for painting. 0212 * @param dim width of the logo 0213 * @return A QPixmap of the logo 0214 */ 0215 AMAROKCORE_EXPORT QPixmap semiTransparentLogo( int dim ); 0216 0217 inline const char* discogsApiKey() { return "91734dd989"; } 0218 inline const char* lastfmApiKey() { return "402d3ca8e9bc9d3cf9b85e1202944ca5"; } 0219 inline const char* lastfmApiSharedSecret() { return "fe0dcde9fcd14c2d1d50665b646335e9"; } 0220 inline const char* flickrApiKey() { return "9c5a288116c34c17ecee37877397fe31"; } 0221 } 0222 0223 #endif