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