optionsWidget.hh 4.53 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 64 65
private slots:
   /// Hide widget, Update Options and tell others about changed Options
   void slotApply();
66

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

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

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

Jan Möbius's avatar
Jan Möbius committed
76 77
   /// open a dialog to determine the color
   void getBackgroundColor();
78

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

   void keyTreeDoubleClicked(QTreeWidgetItem* _item, int col);

   void updateShortcut();

Jan Möbius's avatar
Jan Möbius committed
86 87
protected:
   void showEvent ( QShowEvent * event );
Dirk Wilden's avatar
Dirk Wilden committed
88

Jan Möbius's avatar
Jan Möbius committed
89
private:
Dirk Wilden's avatar
Dirk Wilden committed
90

Jan Möbius's avatar
Jan Möbius committed
91 92 93
   //key-bindings
   std::vector<PluginInfo>& plugins_;
   std::vector<KeyBinding>& coreKeys_;
Jan Möbius's avatar
Jan Möbius committed
94

Dirk Wilden's avatar
Dirk Wilden committed
95 96 97 98 99 100 101 102
   InverseKeyMap& keys_;

   int getPluginInfo(QString pluginName);

   void initKeyTree();

   void applyShortcuts();

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

Jan Möbius's avatar
Jan Möbius committed
106 107
   // Id of the current request
   int httpGetId;
Jan Möbius's avatar
Jan Möbius committed
108

Jan Möbius's avatar
Jan Möbius committed
109 110
   // Request variable
   QHttp *http;
Jan Möbius's avatar
Jan Möbius committed
111

Jan Möbius's avatar
Jan Möbius committed
112 113
   // File for http downloads
   QFile *file;
Jan Möbius's avatar
Jan Möbius committed
114

Jan Möbius's avatar
Jan Möbius committed
115 116
   // ProgressDialog for Downloads
   QProgressDialog *progressDialog;
Jan Möbius's avatar
Jan Möbius committed
117

Jan Möbius's avatar
Jan Möbius committed
118 119
   // What type of download is currently active
   enum DOWNLOAD {
Jan Möbius's avatar
Jan Möbius committed
120 121
      NONE,
      VERSIONS_FILE,
Jan Möbius's avatar
Jan Möbius committed
122
      PLUGIN,
Jan Möbius's avatar
Jan Möbius committed
123
      WINDOWS_SETUP
Jan Möbius's avatar
Jan Möbius committed
124
   } downloadType;
Jan Möbius's avatar
Jan Möbius committed
125

Jan Möbius's avatar
Jan Möbius committed
126 127 128
private:
   /// Starts the download of the given file
   void startDownload( QString _url );
Jan Möbius's avatar
Jan Möbius committed
129

Jan Möbius's avatar
Jan Möbius committed
130 131
   /// Compares the versions from the downloaded Versions file with the current versions
   void compareVersions();
132

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

Jan Möbius's avatar
Jan Möbius committed
136 137
   /// Redraws the version table
   void updateVersionsTable();
Jan Möbius's avatar
Jan Möbius committed
138

Jan Möbius's avatar
Jan Möbius committed
139
private slots:
Jan Möbius's avatar
Jan Möbius committed
140

Jan Möbius's avatar
Jan Möbius committed
141 142
   // 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
143

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

Jan Möbius's avatar
Jan Möbius committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
   // 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
168 169


170 171 172
};

#endif //OPTIONSWIDGET_HH