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 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 28 | #include <QtGui> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 29 | #include <QWidget> |
| 30 | #include <QSystemTrayIcon> |
| 31 | #include <QMenu> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 32 | #include <QDebug> |
| 33 | #include <QProcess> |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 34 | #include <QSettings> |
| 35 | #include <QDir> |
| 36 | #include <QFileDialog> |
| 37 | #include <QCloseEvent> |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 38 | #include <QMessageBox> |
Jared Lindblom | 9d8a5b1 | 2013-01-20 15:21:17 -0800 | [diff] [blame] | 39 | #include <QApplication> |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 40 | |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 41 | #include "fs-watcher.h" |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 42 | #include "dispatcher.h" |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 43 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 44 | class ChronoShareGui : public QDialog |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 45 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 46 | Q_OBJECT |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 47 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 48 | public: |
| 49 | // constructor |
| 50 | explicit ChronoShareGui(QWidget* parent = 0); |
| 51 | |
| 52 | // destructor |
| 53 | ~ChronoShareGui(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 54 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 55 | private slots: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 56 | // open the shared folder |
| 57 | void openSharedFolder(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 58 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 59 | // open file dialog |
| 60 | void openFileDialog(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 62 | // handle left click of tray icon |
| 63 | void trayIconClicked(QSystemTrayIcon::ActivationReason reason); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 65 | // view chronoshare settings |
| 66 | void viewSettings(); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 67 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 68 | // change chronoshare settings |
| 69 | void changeSettings(); |
| 70 | |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame^] | 71 | // click on adhoc button |
| 72 | void onAdHocChange (bool state); // cannot be protected with #ifdef. otherwise something fishy with QT |
| 73 | |
| 74 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 75 | private: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 76 | // create actions that result from clicking a menu option |
| 77 | void createActions(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 78 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 79 | // create tray icon |
| 80 | void createTrayIcon(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 81 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 82 | // set icon image |
| 83 | void setIcon(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 84 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 85 | // load persistent settings |
| 86 | bool loadSettings(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 88 | // save persistent settings |
| 89 | void saveSettings(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 90 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 91 | // prompt user dialog box |
| 92 | void openMessageBox(QString title, QString text); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 93 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 94 | // overload |
| 95 | void openMessageBox(QString title, QString text, QString infotext); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 97 | // capture close event |
| 98 | void closeEvent(QCloseEvent* event); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 99 | |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 100 | // starts fs watcher and dispatcher |
| 101 | void |
| 102 | startBackend(); |
| 103 | |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 104 | private: |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 105 | QSystemTrayIcon* m_trayIcon; // tray icon |
| 106 | QMenu* m_trayIconMenu; // tray icon menu |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 107 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 108 | QAction* m_openFolder; // open the shared folder action |
| 109 | QAction* m_viewSettings; // chronoShare settings |
| 110 | QAction* m_changeFolder; // change the shared folder action |
| 111 | QAction* m_quitProgram; // quit program action |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 112 | |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame^] | 113 | QAction *m_wifiAction; |
| 114 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 115 | QString m_dirPath; // shared directory |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 116 | QString m_username; // username |
| 117 | QString m_sharedFolderName; // shared folder name |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 118 | |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 119 | FsWatcher *m_watcher; |
| 120 | Dispatcher *m_dispatcher; |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 121 | |
| 122 | QLabel* labelUsername; |
| 123 | QPushButton* button; |
| 124 | QLabel* labelSharedFolder; |
| 125 | QLabel* labelSharedFolderPath; |
| 126 | QLineEdit* editUsername; |
| 127 | QLineEdit* editSharedFolder; |
| 128 | QLineEdit* editSharedFolderPath; |
| 129 | QLabel *label; |
| 130 | QVBoxLayout *mainLayout; |
| 131 | |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame^] | 132 | #ifdef ADHOC_SUPPORTED |
| 133 | Executor m_executor; |
| 134 | #endif |
| 135 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 136 | // QString m_settingsFilePath; // settings file path |
| 137 | // QString m_settings; |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | #endif // CHRONOSHAREGUI_H |