blob: 755c63365cd512a2d0cbb737abf6fbcd9f398d5d [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016, Regents of the University of California.
Jared Lindblom06405c42013-01-17 20:48:39 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Jared Lindblom06405c42013-01-17 20:48:39 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * 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 Lindblom06405c42013-01-17 20:48:39 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * 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 Lindblom06405c42013-01-17 20:48:39 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * 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 Lindblom06405c42013-01-17 20:48:39 -080019 */
20
21#ifndef CHRONOSHAREGUI_H
22#define CHRONOSHAREGUI_H
23
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080024#include "adhoc.hpp"
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080025
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080026#if __APPLE__ && HAVE_SPARKLE
27#define SPARKLE_SUPPORTED 1
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080028#include "sparkle-auto-update.hpp"
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080029#endif
30
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080031#include <QApplication>
32#include <QCloseEvent>
Jared Lindblom06405c42013-01-17 20:48:39 -080033#include <QDebug>
Jared Lindblomb4032e22013-01-17 23:50:51 -080034#include <QDir>
35#include <QFileDialog>
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080036#include <QMenu>
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080037#include <QMessageBox>
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080038#include <QProcess>
39#include <QSettings>
40#include <QSystemTrayIcon>
41#include <QWidget>
42#include <QtGui>
Jared Lindblom06405c42013-01-17 20:48:39 -080043
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080044#include "dispatcher.hpp"
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080045#include "fs-watcher.hpp"
Zhenkai Zhud9429222013-02-25 22:34:09 -080046#include "server.hpp"
47#include <boost/thread/thread.hpp>
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080048
Jared Lindblomc8ffd592013-01-25 00:00:30 -080049class ChronoShareGui : public QDialog
Jared Lindblom06405c42013-01-17 20:48:39 -080050{
Alexander Afanasyev83a53002013-01-24 11:12:01 -080051 Q_OBJECT
Jared Lindblom06405c42013-01-17 20:48:39 -080052
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080053public:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080054 // constructor
55 explicit ChronoShareGui(QWidget* parent = 0);
56
57 // destructor
58 ~ChronoShareGui();
Jared Lindblomb4032e22013-01-17 23:50:51 -080059
Jared Lindblom06405c42013-01-17 20:48:39 -080060private slots:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080061 // open the shared folder
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080062 void
63 openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -080064
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080065 void
66 openFile();
Zhenkai Zhu25e13582013-02-27 15:33:01 -080067
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080068 void
69 openInWebBrowser();
Zhenkai Zhu25e13582013-02-27 15:33:01 -080070
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080071 void
72 updateRecentFilesMenu();
Zhenkai Zhu25e13582013-02-27 15:33:01 -080073
Alexander Afanasyev83a53002013-01-24 11:12:01 -080074 // open file dialog
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080075 void
76 openFileDialog();
Jared Lindblomb4032e22013-01-17 23:50:51 -080077
Alexander Afanasyev83a53002013-01-24 11:12:01 -080078 // handle left click of tray icon
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080079 void
80 trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Jared Lindblom06405c42013-01-17 20:48:39 -080081
Alexander Afanasyev83a53002013-01-24 11:12:01 -080082 // view chronoshare settings
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080083 void
84 viewSettings();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080085
Jared Lindblomc8ffd592013-01-25 00:00:30 -080086 // change chronoshare settings
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080087 void
88 changeSettings();
Jared Lindblomc8ffd592013-01-25 00:00:30 -080089
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080090 // click on adhoc button
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080091 void
92 onAdHocChange(bool state); // cannot be protected with #ifdef. otherwise something fishy with QT
Zhenkai Zhu249fbc72013-02-27 21:50:25 -080093
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080094 void
95 onCheckForUpdates();
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080096
Jared Lindblom06405c42013-01-17 20:48:39 -080097private:
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080098 void
99 checkFileAction(const std::string&, int, int);
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800100 // create actions that result from clicking a menu option
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800101 void
102 createActionsAndMenu();
Jared Lindblom06405c42013-01-17 20:48:39 -0800103
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800104 // create tray icon
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800105 void
106 createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -0800107
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800108 // set icon image
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800109 void
110 setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -0800111
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800112 // load persistent settings
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800113 bool
114 loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800115
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800116 // save persistent settings
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800117 void
118 saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800119
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800120 // prompt user dialog box
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800121 void
122 openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800123
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800124 // overload
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800125 void
126 openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800127
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800128 // capture close event
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800129 void
130 closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -0800131
Alexander Afanasyevd437ffc2013-03-04 12:29:23 -0800132 // starts/restarts fs watcher and dispatcher
Zhenkai Zhud5756312013-01-31 13:49:45 -0800133 void
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800134 startBackend(bool restart = false);
Zhenkai Zhud5756312013-01-31 13:49:45 -0800135
Jared Lindblom06405c42013-01-17 20:48:39 -0800136private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800137 QSystemTrayIcon* m_trayIcon; // tray icon
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800138 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -0800139
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800140 QAction* m_openFolder; // open the shared folder action
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800141 QAction* m_viewSettings; // chronoShare settings
142 QAction* m_changeFolder; // change the shared folder action
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800143 QAction* m_quitProgram; // quit program action
144 QAction* m_checkForUpdates;
145 QAction* m_openWeb;
146 QMenu* m_recentFilesMenu;
147 QAction* m_fileActions[5];
Jared Lindblom06405c42013-01-17 20:48:39 -0800148
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800149 QAction* m_wifiAction;
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800150
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800151 QString m_dirPath; // shared directory
152 QString m_username; // username
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800153 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800154
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800155 FsWatcher* m_watcher;
156 Dispatcher* m_dispatcher;
157 http::server::server* m_httpServer;
Zhenkai Zhud9429222013-02-25 22:34:09 -0800158 boost::thread m_httpServerThread;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800159
160 QLabel* labelUsername;
161 QPushButton* button;
162 QLabel* labelSharedFolder;
163 QLabel* labelSharedFolderPath;
164 QLineEdit* editUsername;
165 QLineEdit* editSharedFolder;
166 QLineEdit* editSharedFolderPath;
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800167 QLabel* label;
168 QVBoxLayout* mainLayout;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800169
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800170#ifdef ADHOC_SUPPORTED
171 Executor m_executor;
172#endif
173
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800174#ifdef SPARKLE_SUPPORTED
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800175 AutoUpdate* m_autoUpdate;
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800176#endif
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800177 // QString m_settingsFilePath; // settings file path
178 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800179};
180
181#endif // CHRONOSHAREGUI_H