OpenMW
apps/launcher/datafilespage.hpp
Go to the documentation of this file.
00001 #ifndef DATAFILESPAGE_H
00002 #define DATAFILESPAGE_H
00003 
00004 #include "ui_datafilespage.h"
00005 #include <QWidget>
00006 
00007 
00008 #include <QDir>
00009 #include <QFile>
00010 
00011 class QSortFilterProxyModel;
00012 class QAbstractItemModel;
00013 class QMenu;
00014 
00015 namespace Files { struct ConfigurationManager; }
00016 namespace ContentSelectorView { class ContentSelector; }
00017 
00018 namespace Launcher
00019 {
00020     class TextInputDialog;
00021     class GameSettings;
00022     class LauncherSettings;
00023     class ProfilesComboBox;
00024 
00025     class DataFilesPage : public QWidget
00026     {
00027         Q_OBJECT
00028 
00029         ContentSelectorView::ContentSelector *mSelector;
00030         Ui::DataFilesPage ui;
00031 
00032     public:
00033         explicit DataFilesPage (Files::ConfigurationManager &cfg, GameSettings &gameSettings,
00034                                 LauncherSettings &launcherSettings, QWidget *parent = 0);
00035 
00036         QAbstractItemModel* profilesModel() const;
00037 
00038         int profilesIndex() const;
00039 
00040         //void writeConfig(QString profile = QString());
00041         void saveSettings(const QString &profile = "");
00042         void loadSettings();
00043 
00044     signals:
00045         void signalProfileChanged (int index);
00046 
00047     public slots:
00048         void slotProfileChanged (int index);
00049 
00050     private slots:
00051 
00052         void slotProfileChangedByUser(const QString &previous, const QString &current);
00053         void slotProfileRenamed(const QString &previous, const QString &current);
00054         void slotProfileDeleted(const QString &item);
00055 
00056         void on_newProfileAction_triggered();
00057         void on_deleteProfileAction_triggered();
00058 
00059     private:
00060 
00061         QMenu *mContextMenu;
00062 
00063         Files::ConfigurationManager &mCfgMgr;
00064 
00065         GameSettings &mGameSettings;
00066         LauncherSettings &mLauncherSettings;
00067 
00068         QString mDataLocal;
00069 
00070         void setPluginsCheckstates(Qt::CheckState state);
00071 
00072         void buildView();
00073         void setupDataFiles();
00074         void setupConfig();
00075         void readConfig();
00076         void setProfile (int index, bool savePrevious);
00077         void setProfile (const QString &previous, const QString &current, bool savePrevious);
00078         void removeProfile (const QString &profile);
00079         bool showDeleteMessageBox (const QString &text);
00080         void addProfile (const QString &profile, bool setAsCurrent);
00081         void checkForDefaultProfile();
00082 
00083         class PathIterator
00084         {
00085             QStringList::ConstIterator mCitEnd;
00086             QStringList::ConstIterator mCitCurrent;
00087             QStringList::ConstIterator mCitBegin;
00088             QString mFile;
00089             QString mFilePath;
00090 
00091         public:
00092             PathIterator (const QStringList &list)
00093             {
00094                 mCitBegin = list.constBegin();
00095                 mCitCurrent = mCitBegin;
00096                 mCitEnd = list.constEnd();
00097             }
00098 
00099             QString findFirstPath (const QString &file)
00100             {
00101                 mCitCurrent = mCitBegin;
00102                 mFile = file;
00103                 return path();
00104             }
00105 
00106             QString findNextPath () { return path(); }
00107 
00108         private:
00109 
00110             QString path ()
00111             {
00112                 bool success = false;
00113                 QDir dir;
00114                 QFileInfo file;
00115 
00116                 while (!success)
00117                 {
00118                     if (mCitCurrent == mCitEnd)
00119                         break;
00120 
00121                     dir.setPath (*(mCitCurrent++));
00122                     file.setFile (dir.absoluteFilePath (mFile));
00123 
00124                     success = file.exists();
00125                 }
00126 
00127                 if (success)
00128                     return file.absoluteFilePath();
00129 
00130                 return "";
00131             }
00132 
00133         };
00134     };
00135 }
00136 #endif