blob: 9721b396505cbd3f3954475342cb806f0cc4677a [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
Jared Lindblomc8ffd592013-01-25 00:00:30 -080031#include <QtGui>
Jared Lindblom06405c42013-01-17 20:48:39 -080032#include <QWidget>
33#include <QSystemTrayIcon>
34#include <QMenu>
Jared Lindblom06405c42013-01-17 20:48:39 -080035#include <QDebug>
36#include <QProcess>
Jared Lindblomb4032e22013-01-17 23:50:51 -080037#include <QSettings>
38#include <QDir>
39#include <QFileDialog>
40#include <QCloseEvent>
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080041#include <QMessageBox>
Jared Lindblom9d8a5b12013-01-20 15:21:17 -080042#include <QApplication>
Jared Lindblom06405c42013-01-17 20:48:39 -080043
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080044#include "fs-watcher.hpp"
45#include "dispatcher.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 Afanasyev83a53002013-01-24 11:12:01 -080053 public:
54 // 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
62 void openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -080063
Zhenkai Zhu25e13582013-02-27 15:33:01 -080064 void openFile();
65
66 void openInWebBrowser();
67
68 void updateRecentFilesMenu();
69
Alexander Afanasyev83a53002013-01-24 11:12:01 -080070 // open file dialog
71 void openFileDialog();
Jared Lindblomb4032e22013-01-17 23:50:51 -080072
Alexander Afanasyev83a53002013-01-24 11:12:01 -080073 // handle left click of tray icon
74 void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Jared Lindblom06405c42013-01-17 20:48:39 -080075
Alexander Afanasyev83a53002013-01-24 11:12:01 -080076 // view chronoshare settings
77 void viewSettings();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080078
Jared Lindblomc8ffd592013-01-25 00:00:30 -080079 // change chronoshare settings
80 void changeSettings();
81
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080082 // click on adhoc button
83 void onAdHocChange (bool state); // cannot be protected with #ifdef. otherwise something fishy with QT
Zhenkai Zhu249fbc72013-02-27 21:50:25 -080084
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080085 void onCheckForUpdates();
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080086
Jared Lindblom06405c42013-01-17 20:48:39 -080087private:
Zhenkai Zhu25e13582013-02-27 15:33:01 -080088 void checkFileAction(const std::string &, int, int);
Alexander Afanasyev83a53002013-01-24 11:12:01 -080089 // create actions that result from clicking a menu option
Zhenkai Zhu25e13582013-02-27 15:33:01 -080090 void createActionsAndMenu();
Jared Lindblom06405c42013-01-17 20:48:39 -080091
Alexander Afanasyev83a53002013-01-24 11:12:01 -080092 // create tray icon
93 void createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080094
Alexander Afanasyev83a53002013-01-24 11:12:01 -080095 // set icon image
96 void setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080097
Alexander Afanasyev83a53002013-01-24 11:12:01 -080098 // load persistent settings
99 bool loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800100
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800101 // save persistent settings
102 void saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800103
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800104 // prompt user dialog box
105 void openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800106
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800107 // overload
108 void openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800109
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800110 // capture close event
111 void closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -0800112
Alexander Afanasyevd437ffc2013-03-04 12:29:23 -0800113 // starts/restarts fs watcher and dispatcher
Zhenkai Zhud5756312013-01-31 13:49:45 -0800114 void
Alexander Afanasyevd437ffc2013-03-04 12:29:23 -0800115 startBackend(bool restart=false);
Zhenkai Zhud5756312013-01-31 13:49:45 -0800116
Jared Lindblom06405c42013-01-17 20:48:39 -0800117private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800118 QSystemTrayIcon* m_trayIcon; // tray icon
119 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -0800120
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800121 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 Zhuaca6cb52013-02-24 23:34:03 -0800125 QAction *m_checkForUpdates;
Zhenkai Zhu25e13582013-02-27 15:33:01 -0800126 QAction *m_openWeb;
127 QMenu *m_recentFilesMenu;
128 QAction *m_fileActions[5];
Jared Lindblom06405c42013-01-17 20:48:39 -0800129
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800130 QAction *m_wifiAction;
131
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800132 QString m_dirPath; // shared directory
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800133 QString m_username; // username
134 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800135
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800136 FsWatcher *m_watcher;
137 Dispatcher *m_dispatcher;
Zhenkai Zhud9429222013-02-25 22:34:09 -0800138 http::server::server *m_httpServer;
139 boost::thread m_httpServerThread;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800140
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 Afanasyev85a4ba02013-02-24 16:30:17 -0800151#ifdef ADHOC_SUPPORTED
152 Executor m_executor;
153#endif
154
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800155#ifdef SPARKLE_SUPPORTED
156 AutoUpdate *m_autoUpdate;
157#endif
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800158 // QString m_settingsFilePath; // settings file path
159 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800160};
161
162#endif // CHRONOSHAREGUI_H