optionsWidget.hh 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
Jan Möbius's avatar
Jan Möbius committed
15
//
16 17 18 19
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
Jan Möbius's avatar
Jan Möbius committed
20
//
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision: 1909 $
//   $Author: wilden $
//   $Date: 2008-06-03 18:45:21 +0200 (Tue, 03 Jun 2008) $
//
//=============================================================================




#ifndef OPTIONSWIDGET_HH
#define OPTIONSWIDGET_HH

38
#include "ui_optionsWidget.hh"
39 40
#include <QtGui>
#include <QStringList>
Jan Möbius's avatar
Jan Möbius committed
41
#include <QtNetwork>
42

Dirk Wilden's avatar
Dirk Wilden committed
43 44
#include <OpenFlipper/Core/PluginInfo.hh>

Dirk Wilden's avatar
Dirk Wilden committed
45 46 47 48
//map for keyBindings
typedef std::multimap< std::pair< QObject*, int >, std::pair< int, Qt::KeyboardModifiers > > InverseKeyMap;


49 50
class OptionsWidget : public QWidget, public Ui::OptionsWidget
{
Jan Möbius's avatar
Jan Möbius committed
51

Jan Möbius's avatar
Jan Möbius committed
52
Q_OBJECT
53

Jan Möbius's avatar
Jan Möbius committed
54
public:
Dirk Wilden's avatar
Dirk Wilden committed
55
   OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, InverseKeyMap& _invKeys, QWidget* parent =0 );
56

Jan Möbius's avatar
Jan Möbius committed
57 58 59
signals:
   void applyOptions();
   void saveOptions();
60

Dirk Wilden's avatar
Dirk Wilden committed
61 62
   void addKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject* _plugin, int _keyBindingID);

Jan Möbius's avatar
Jan Möbius committed
63
private slots:
Dirk Wilden's avatar
Dirk Wilden committed
64 65 66
   /// call slotApply and hide widget
   void slotOk();
   /// Update Options and tell others about changed Options
Jan Möbius's avatar
Jan Möbius committed
67
   void slotApply();
68

Jan Möbius's avatar
Jan Möbius committed
69 70
   /// Only hide widget
   void slotCancel();
Jan Möbius's avatar
Jan Möbius committed
71

Jan Möbius's avatar
Jan Möbius committed
72 73
   /// Checks for updates
   void slotCheckUpdates();
Jan Möbius's avatar
Jan Möbius committed
74

Jan Möbius's avatar
Jan Möbius committed
75 76
   /// Download updates
   void slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
77

Jan Möbius's avatar
Jan Möbius committed
78 79
   /// open a dialog to determine the color
   void getBackgroundColor();
80
   void getBaseColor();
81

Dirk Wilden's avatar
Dirk Wilden committed
82 83 84 85 86 87 88
   /// keyBinding TreeWidget-Item changed
   void keyTreeItemChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous );

   void keyTreeDoubleClicked(QTreeWidgetItem* _item, int col);

   void updateShortcut();

Dirk Wilden's avatar
Dirk Wilden committed
89 90
   void slotShowPluginOptions(const QString& _pluginName );

91 92 93
   ///restore keyBinding Presets
   void restoreKeyPresets();

Jan Möbius's avatar
Jan Möbius committed
94 95
protected:
   void showEvent ( QShowEvent * event );
Dirk Wilden's avatar
Dirk Wilden committed
96

Jan Möbius's avatar
Jan Möbius committed
97
private:
Dirk Wilden's avatar
Dirk Wilden committed
98

Dirk Wilden's avatar
Dirk Wilden committed
99 100 101 102 103
   // plugin Options
   void initPluginOptions();

   QVBoxLayout* pluginOptionsLayout;

Jan Möbius's avatar
Jan Möbius committed
104 105 106
   //key-bindings
   std::vector<PluginInfo>& plugins_;
   std::vector<KeyBinding>& coreKeys_;
Jan Möbius's avatar
Jan Möbius committed
107

Dirk Wilden's avatar
Dirk Wilden committed
108 109 110 111 112 113 114 115
   InverseKeyMap& keys_;

   int getPluginInfo(QString pluginName);

   void initKeyTree();

   void applyShortcuts();

Jan Möbius's avatar
Jan Möbius committed
116 117
   // flag indicating if something went wrong and the request has to be aborted
   bool httpRequestAborted;
Jan Möbius's avatar
Jan Möbius committed
118

Jan Möbius's avatar
Jan Möbius committed
119 120
   // Id of the current request
   int httpGetId;
Jan Möbius's avatar
Jan Möbius committed
121

Jan Möbius's avatar
Jan Möbius committed
122 123
   // Request variable
   QHttp *http;
Jan Möbius's avatar
Jan Möbius committed
124

Jan Möbius's avatar
Jan Möbius committed
125 126
   // File for http downloads
   QFile *file;
Jan Möbius's avatar
Jan Möbius committed
127

Jan Möbius's avatar
Jan Möbius committed
128 129
   // ProgressDialog for Downloads
   QProgressDialog *progressDialog;
Jan Möbius's avatar
Jan Möbius committed
130

Jan Möbius's avatar
Jan Möbius committed
131 132
   // What type of download is currently active
   enum DOWNLOAD {
Jan Möbius's avatar
Jan Möbius committed
133 134
      NONE,
      VERSIONS_FILE,
Jan Möbius's avatar
Jan Möbius committed
135
      PLUGIN,
Jan Möbius's avatar
Jan Möbius committed
136
      WINDOWS_SETUP
Jan Möbius's avatar
Jan Möbius committed
137
   } downloadType;
Jan Möbius's avatar
Jan Möbius committed
138

Jan Möbius's avatar
Jan Möbius committed
139 140 141
private:
   /// Starts the download of the given file
   void startDownload( QString _url );
Jan Möbius's avatar
Jan Möbius committed
142

Jan Möbius's avatar
Jan Möbius committed
143 144
   /// Compares the versions from the downloaded Versions file with the current versions
   void compareVersions();
145

Jan Möbius's avatar
Jan Möbius committed
146 147
   /// Compares two version strings and returns if a newer Version is available
   bool isNewer(QString _current, QString _latest);
148

Jan Möbius's avatar
Jan Möbius committed
149 150
   /// Redraws the version table
   void updateVersionsTable();
Jan Möbius's avatar
Jan Möbius committed
151

Jan Möbius's avatar
Jan Möbius committed
152
private slots:
Jan Möbius's avatar
Jan Möbius committed
153

Jan Möbius's avatar
Jan Möbius committed
154 155
   // This slot is called when a http request has been finished
   void httpRequestFinished(int requestId, bool error);
Jan Möbius's avatar
Jan Möbius committed
156

Jan Möbius's avatar
Jan Möbius committed
157 158
   // Parses the response and gives feedback
   void readResponseHeader(const QHttpResponseHeader &responseHeader);
Jan Möbius's avatar
Jan Möbius committed
159

Jan Möbius's avatar
Jan Möbius committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
   // Updates the progress Dialog while downloading
   void updateDataReadProgress(int bytesRead, int totalBytes);

   // Progress dialog callback for cancel
   void cancelDownload();

   // Update component of OpenFlipper
   void updateComponent();

private:
   /** After checking for updates this variable will contain a list of filenames for which updates are available
    */
   QStringList updatedPlugins_;

   /** Here the architecture specific path for plugins will be created
    */
   QString pluginPath_;

   /** Current filename of the plugin to be updated
    */
   QString currentUpdateName_;
Jan Möbius's avatar
Jan Möbius committed
181 182


183 184 185
};

#endif //OPTIONSWIDGET_HH