Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017, 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 | |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 21 | #ifndef CHRONOSHARE_GUI_CHRONOSHAREGUI_HPP |
| 22 | #define CHRONOSHARE_GUI_CHRONOSHAREGUI_HPP |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 23 | |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 24 | #include "core/chronoshare-common.hpp" |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 26 | #include <QApplication> |
| 27 | #include <QCloseEvent> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 28 | #include <QDebug> |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 29 | #include <QDir> |
| 30 | #include <QFileDialog> |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 31 | #include <QMenu> |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 32 | #include <QMessageBox> |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 33 | #include <QProcess> |
| 34 | #include <QSettings> |
| 35 | #include <QSystemTrayIcon> |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 36 | #include <QtWidgets> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 37 | |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 38 | #ifndef Q_MOC_RUN |
| 39 | #include "adhoc.hpp" |
Alexander Afanasyev | f4cde4e | 2016-12-25 13:42:57 -0800 | [diff] [blame] | 40 | #include "dispatcher.hpp" |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 41 | #include "fs-watcher.hpp" |
Zhenkai Zhu | d942922 | 2013-02-25 22:34:09 -0800 | [diff] [blame] | 42 | #include "server.hpp" |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 43 | #endif // Q_MOC_RUN |
| 44 | |
| 45 | #if __APPLE__ && HAVE_SPARKLE |
| 46 | #define SPARKLE_SUPPORTED 1 |
| 47 | #include "sparkle-auto-update.hpp" |
| 48 | #endif |
| 49 | |
| 50 | #include <thread> |
| 51 | |
| 52 | namespace ndn { |
| 53 | namespace chronoshare { |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 54 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 55 | class ChronoShareGui : public QDialog |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 56 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 57 | Q_OBJECT |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 58 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 59 | public: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 60 | // constructor |
| 61 | explicit ChronoShareGui(QWidget* parent = 0); |
| 62 | |
| 63 | // destructor |
| 64 | ~ChronoShareGui(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 65 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 66 | private slots: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 67 | // open the shared folder |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 68 | void |
| 69 | openSharedFolder(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 71 | void |
| 72 | openFile(); |
Zhenkai Zhu | 25e1358 | 2013-02-27 15:33:01 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 74 | void |
| 75 | openInWebBrowser(); |
Zhenkai Zhu | 25e1358 | 2013-02-27 15:33:01 -0800 | [diff] [blame] | 76 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 77 | void |
| 78 | updateRecentFilesMenu(); |
Zhenkai Zhu | 25e1358 | 2013-02-27 15:33:01 -0800 | [diff] [blame] | 79 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 80 | // open file dialog |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 81 | void |
| 82 | openFileDialog(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 83 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 84 | // handle left click of tray icon |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 85 | void |
| 86 | trayIconClicked(QSystemTrayIcon::ActivationReason reason); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 88 | // view chronoshare settings |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 89 | void |
| 90 | viewSettings(); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 91 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 92 | // change chronoshare settings |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 93 | void |
| 94 | changeSettings(); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 96 | void |
| 97 | onCheckForUpdates(); |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 98 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 99 | private: |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 100 | void |
| 101 | checkFileAction(const std::string&, int, int); |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 102 | // create actions that result from clicking a menu option |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 103 | void |
| 104 | createActionsAndMenu(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 106 | // create tray icon |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 107 | void |
| 108 | createTrayIcon(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 110 | // set icon image |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 111 | void |
| 112 | setIcon(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 113 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 114 | // load persistent settings |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 115 | bool |
| 116 | loadSettings(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 117 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 118 | // save persistent settings |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 119 | void |
| 120 | saveSettings(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 121 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 122 | // prompt user dialog box |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 123 | void |
| 124 | openMessageBox(QString title, QString text); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 125 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 126 | // overload |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 127 | void |
| 128 | openMessageBox(QString title, QString text, QString infotext); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 130 | // capture close event |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 131 | void |
| 132 | closeEvent(QCloseEvent* event); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | d437ffc | 2013-03-04 12:29:23 -0800 | [diff] [blame] | 134 | // starts/restarts fs watcher and dispatcher |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 135 | void |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 136 | startBackend(bool restart = false); |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 137 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 138 | private: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 139 | QSystemTrayIcon* m_trayIcon; // tray icon |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 140 | QMenu* m_trayIconMenu; // tray icon menu |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 141 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 142 | QAction* m_openFolder; // open the shared folder action |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 143 | QAction* m_viewSettings; // chronoShare settings |
| 144 | QAction* m_changeFolder; // change the shared folder action |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 145 | QAction* m_quitProgram; // quit program action |
| 146 | QAction* m_checkForUpdates; |
| 147 | QAction* m_openWeb; |
| 148 | QMenu* m_recentFilesMenu; |
| 149 | QAction* m_fileActions[5]; |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 150 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 151 | QAction* m_wifiAction; |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 152 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 153 | QString m_dirPath; // shared directory |
| 154 | QString m_username; // username |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 155 | QString m_sharedFolderName; // shared folder name |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 156 | |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 157 | http::server::server* m_httpServer; |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 158 | std::thread m_httpServerThread; |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 159 | |
| 160 | QLabel* labelUsername; |
| 161 | QPushButton* button; |
| 162 | QLabel* labelSharedFolder; |
| 163 | QLabel* labelSharedFolderPath; |
| 164 | QLineEdit* editUsername; |
| 165 | QLineEdit* editSharedFolder; |
| 166 | QLineEdit* editSharedFolderPath; |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 167 | QLabel* label; |
| 168 | QVBoxLayout* mainLayout; |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 169 | |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 170 | #ifdef SPARKLE_SUPPORTED |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 171 | AutoUpdate* m_autoUpdate; |
Zhenkai Zhu | aca6cb5 | 2013-02-24 23:34:03 -0800 | [diff] [blame] | 172 | #endif |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 173 | // QString m_settingsFilePath; // settings file path |
| 174 | // QString m_settings; |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 175 | |
| 176 | std::thread m_chronoshareThread; |
| 177 | std::unique_ptr<boost::asio::io_service> m_ioService; |
| 178 | std::unique_ptr<Face> m_face; |
| 179 | std::unique_ptr<FsWatcher> m_watcher; |
| 180 | std::unique_ptr<Dispatcher> m_dispatcher; |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 181 | }; |
| 182 | |
Lijing Wang | 152449c | 2015-05-31 16:25:16 -0700 | [diff] [blame^] | 183 | } // namespace chronoshare |
| 184 | } // namespace ndn |
| 185 | |
| 186 | #endif // CHRONOSHARE_GUI_CHRONOSHAREGUI_HPP |