ipodsysinfo.h

00001  /*****************************************************************************
00002  *   Copyright (C) 2004 by Andrew de Quincey                                  *
00003  *   adq@lidskialf.net                                                        *
00004  *   Copyright (C) 2005 by Michael Schulze                                    *
00005  *   mike.s@genion.de                                                         *
00006  *                                                                            *
00007  *  The code contained in this file is free software; you can redistribute    *
00008  *  it and/or modify it under the terms of the GNU Lesser General Public      *
00009  *  License as published by the Free Software Foundation; either version      *
00010  *  2.1 of the License, or (at your option) any later version.                *
00011  *                                                                            *
00012  *  This file is distributed in the hope that it will be useful,              *
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00015  *  Lesser General Public License for more details.                           *
00016  *                                                                            *
00017  *  You should have received a copy of the GNU Lesser General Public          *
00018  *  License along with this code; if not, write to the Free Software          *
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *
00020  *                                                                            *
00021  *  iTunes and iPod are trademarks of Apple                                   *
00022  *                                                                            *
00023  *  This product is not supported/written/published by Apple!                 *
00024  *****************************************************************************/
00025 
00026 #ifndef IPODSYSINFO_H
00027 #define IPODSYSINFO_H
00028 
00029 #include <qobject.h>
00030 #include <qstring.h>
00031 #include <qdir.h>
00032 
00033 #include <map>
00034 
00035 #include "utils.h"
00036 
00037 #define IPOD_CONTROLDIR "iPod_Control"
00038 #define IPOD_MUSICDIR   "Music"
00039 
00040 /**
00041  * @author Andrew de Quincey, Michael Schulze
00042  */
00043 class IPodSysInfo {
00044 
00045     typedef std::map<QString, QString> PropertyMap;
00046 
00047     struct KeyDereferencer {
00048         const QString& operator() ( PropertyMap::const_iterator& iter ) const {
00049             return (*iter).first;
00050         }
00051     };
00052 
00053 public:
00054     typedef itunesdb::utils::DereferencingRangeIterator<QString,PropertyMap::const_iterator, KeyDereferencer> KeyIterator;
00055     IPodSysInfo( const QString& filename );
00056     ~IPodSysInfo();
00057 
00058     /**
00059      * Loads the /Device/SysInfo file and figures out where the music directories are.
00060      */
00061     bool load();
00062 
00063     /**
00064      * Refreshes the statistics about disc space (total space, usage, available space)
00065      */
00066     void refreshDiskUsageStats();
00067 
00068     /**
00069     * Get the keys to all known system information properties.
00070     *
00071     * @return Key list.
00072     */
00073     KeyIterator getKeys() const;
00074 
00075     /**
00076     * Retrieve an individual property by key
00077     *
00078     * @param key The key to look up.
00079     * @return The value, or QString::null if unknown.
00080     */
00081     QString getValue(const QString& key) const;
00082 
00083     /**
00084      * Returns the total disk space available on the device (filesystem wise)
00085      * in kBytes
00086      */
00087     unsigned long getTotalDiskSpaceKB();
00088 
00089     /**
00090      * Returns the currently available disk space on the device (filesystem wise)
00091      * in kBytes
00092      */
00093     unsigned long getAvailableDiskSpaceKB();
00094 
00095     /**
00096      * Returns the currently used disk space on the device (filesystem wise)
00097      * in kBytes
00098      */
00099     unsigned long getUsedDiskSpaceKB();
00100 
00101     /**
00102      * Returns the number of fXX directories inside the "Music" dir
00103      */
00104     int getNumTrackFileDirs() const { return m_numTrackFileDirs; }
00105 
00106     /**
00107      * Returns the directory where the music files reside.
00108      */
00109     const QDir& getMusicDir() const { return m_musicDir; }
00110 
00111     // const QString& getDeviceName() const { return m_deviceName; }
00112 
00113     /**
00114      * Returns the device mountpoint (or drive letter on windows)
00115      */
00116     const QString& getDeviceMountpoint() const { return m_ipodBase; }
00117 
00118     /**
00119      * clears all information from this sysinfo instance.
00120      */
00121     void clear();
00122 
00123     /**
00124      * Returns the path to the "iPod_Control" directory on the iPod.
00125      * @return the path to the "iPod_Control" directory on the iPod.
00126      */
00127     QString getIPodControlDirName() { return QString( m_ipodBase + "/" + IPOD_CONTROLDIR ); }
00128 
00129     /**
00130      * Creates the "Music" directory and the fXX subdirs.
00131      * @return true if successful, false if such a directory already exists
00132      */
00133     bool createMusicDirs();
00134 
00135     /**
00136      * finds the first track filename for the given trackid.
00137      * the track filename will be formed like<br>
00138      * kpod[decimal encoded ID]<br>
00139      * the file extension needs to be added later
00140      */
00141     QString findNewTrackPathInfo( Q_UINT32 id, const QString& fileExtension = QString::null );
00142 
00143 private:
00144 
00145     QDir findMusicDir( const QString& ipodbase, bool * found = NULL ) const;
00146 
00147     void ensureDiskUsageStats();
00148     PropertyMap m_details;
00149     QString m_ipodBase;
00150     // QString m_deviceName;
00151     QDir m_musicDir;
00152     uint m_numTrackFileDirs;
00153 
00154     unsigned long m_kbytesTotal;
00155     unsigned long m_kbytesAvail;
00156 };
00157 
00158 #endif

Generated on Wed Dec 19 00:15:19 2007 for libqtpod by  doxygen 1.5.0