Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2013 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Jared Lindblom <lindblom@cs.ucla.edu> |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifndef CHRONOSHAREGUI_H |
| 24 | #define CHRONOSHAREGUI_H |
| 25 | |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 26 | #include "adhoc.h" |
| 27 | |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 28 | #if __APPLE__ && HAVE_SPARKLE |
| 29 | #define SPARKLE_SUPPORTED 1 |
Zhenkai Zhu | bb170d4 | 2013-02-25 13:48:59 -0800 | [diff] [blame] | 30 | #include "sparkle-auto-update.h" |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 31 | #endif |
| 32 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 33 | #include <QtGui> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 34 | #include <QWidget> |
| 35 | #include <QSystemTrayIcon> |
| 36 | #include <QMenu> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 37 | #include <QDebug> |
| 38 | #include <QProcess> |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 39 | #include <QSettings> |
| 40 | #include <QDir> |
| 41 | #include <QFileDialog> |
| 42 | #include <QCloseEvent> |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 43 | #include <QMessageBox> |
Jared Lindblom | 9d8a5b1 | 2013-01-20 15:21:17 -0800 | [diff] [blame] | 44 | #include <QApplication> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 46 | #include "fs-watcher.h" |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 47 | #include "dispatcher.h" |
Zhenkai Zhu | d942922 | 2013-02-25 22:34:09 -0800 | [diff] [blame] | 48 | #include "server.hpp" |
| 49 | #include <boost/thread/thread.hpp> |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 50 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 51 | class ChronoShareGui : public QDialog |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 52 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 53 | Q_OBJECT |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 55 | public: |
| 56 | // constructor |
| 57 | explicit ChronoShareGui(QWidget* parent = 0); |
| 58 | |
| 59 | // destructor |
| 60 | ~ChronoShareGui(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 61 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 62 | private slots: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 63 | // open the shared folder |
| 64 | void openSharedFolder(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 65 | |
Zhenkai Zhu | 25e1358 | 2013-02-27 15:33:01 -0800 | [diff] [blame^] | 66 | void openFile(); |
| 67 | |
| 68 | void openInWebBrowser(); |
| 69 | |
| 70 | void updateRecentFilesMenu(); |
| 71 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 72 | // open file dialog |
| 73 | void openFileDialog(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 75 | // handle left click of tray icon |
| 76 | void trayIconClicked(QSystemTrayIcon::ActivationReason reason); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 78 | // view chronoshare settings |
| 79 | void viewSettings(); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 80 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 81 | // change chronoshare settings |
| 82 | void changeSettings(); |
| 83 | |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 84 | // click on adhoc button |
| 85 | void onAdHocChange (bool state); // cannot be protected with #ifdef. otherwise something fishy with QT |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 86 | #ifdef SPARKLE_SUPPORTED |
| 87 | void onCheckForUpdates(); |
| 88 | #endif |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 89 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 90 | private: |
Zhenkai Zhu | 25e1358 | 2013-02-27 15:33:01 -0800 | [diff] [blame^] | 91 | void checkFileAction(const std::string &, int, int); |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 92 | // create actions that result from clicking a menu option |
Zhenkai Zhu | 25e1358 | 2013-02-27 15:33:01 -0800 | [diff] [blame^] | 93 | void createActionsAndMenu(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 94 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 95 | // create tray icon |
| 96 | void createTrayIcon(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 98 | // set icon image |
| 99 | void setIcon(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 100 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 101 | // load persistent settings |
| 102 | bool loadSettings(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 103 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 104 | // save persistent settings |
| 105 | void saveSettings(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 107 | // prompt user dialog box |
| 108 | void openMessageBox(QString title, QString text); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 110 | // overload |
| 111 | void openMessageBox(QString title, QString text, QString infotext); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 112 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 113 | // capture close event |
| 114 | void closeEvent(QCloseEvent* event); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 115 | |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 116 | // starts fs watcher and dispatcher |
| 117 | void |
| 118 | startBackend(); |
| 119 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 120 | private: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 121 | QSystemTrayIcon* m_trayIcon; // tray icon |
| 122 | QMenu* m_trayIconMenu; // tray icon menu |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 123 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 124 | QAction* m_openFolder; // open the shared folder action |
| 125 | QAction* m_viewSettings; // chronoShare settings |
| 126 | QAction* m_changeFolder; // change the shared folder action |
| 127 | QAction* m_quitProgram; // quit program action |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 128 | QAction *m_checkForUpdates; |
Zhenkai Zhu | 25e1358 | 2013-02-27 15:33:01 -0800 | [diff] [blame^] | 129 | QAction *m_openWeb; |
| 130 | QMenu *m_recentFilesMenu; |
| 131 | QAction *m_fileActions[5]; |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 132 | |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 133 | QAction *m_wifiAction; |
| 134 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 135 | QString m_dirPath; // shared directory |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 136 | QString m_username; // username |
| 137 | QString m_sharedFolderName; // shared folder name |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 138 | |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 139 | FsWatcher *m_watcher; |
| 140 | Dispatcher *m_dispatcher; |
Zhenkai Zhu | d942922 | 2013-02-25 22:34:09 -0800 | [diff] [blame] | 141 | http::server::server *m_httpServer; |
| 142 | boost::thread m_httpServerThread; |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 143 | |
| 144 | QLabel* labelUsername; |
| 145 | QPushButton* button; |
| 146 | QLabel* labelSharedFolder; |
| 147 | QLabel* labelSharedFolderPath; |
| 148 | QLineEdit* editUsername; |
| 149 | QLineEdit* editSharedFolder; |
| 150 | QLineEdit* editSharedFolderPath; |
| 151 | QLabel *label; |
| 152 | QVBoxLayout *mainLayout; |
| 153 | |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 154 | #ifdef ADHOC_SUPPORTED |
| 155 | Executor m_executor; |
| 156 | #endif |
| 157 | |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 158 | #ifdef SPARKLE_SUPPORTED |
| 159 | AutoUpdate *m_autoUpdate; |
| 160 | #endif |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 161 | // QString m_settingsFilePath; // settings file path |
| 162 | // QString m_settings; |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | #endif // CHRONOSHAREGUI_H |