blob: 9a69d3d9376747b54b3ba95e91296215b9a6a719 [file] [log] [blame]
Jared Lindblom06405c42013-01-17 20:48:39 -08001/* -*- 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 Afanasyev85a4ba02013-02-24 16:30:17 -080019 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
Jared Lindblom06405c42013-01-17 20:48:39 -080021 */
22
23#ifndef CHRONOSHAREGUI_H
24#define CHRONOSHAREGUI_H
25
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080026#include "adhoc.hpp"
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080027
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080028#if __APPLE__ && HAVE_SPARKLE
29#define SPARKLE_SUPPORTED 1
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080030#include "sparkle-auto-update.hpp"
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080031#endif
32
Jared Lindblomc8ffd592013-01-25 00:00:30 -080033#include <QtGui>
Jared Lindblom06405c42013-01-17 20:48:39 -080034#include <QWidget>
35#include <QSystemTrayIcon>
36#include <QMenu>
Jared Lindblom06405c42013-01-17 20:48:39 -080037#include <QDebug>
38#include <QProcess>
Jared Lindblomb4032e22013-01-17 23:50:51 -080039#include <QSettings>
40#include <QDir>
41#include <QFileDialog>
42#include <QCloseEvent>
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080043#include <QMessageBox>
Jared Lindblom9d8a5b12013-01-20 15:21:17 -080044#include <QApplication>
Jared Lindblom06405c42013-01-17 20:48:39 -080045
Alexander Afanasyevf4cde4e2016-12-25 13:42:57 -080046#include "fs-watcher.hpp"
47#include "dispatcher.hpp"
Zhenkai Zhud9429222013-02-25 22:34:09 -080048#include "server.hpp"
49#include <boost/thread/thread.hpp>
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080050
Jared Lindblomc8ffd592013-01-25 00:00:30 -080051class ChronoShareGui : public QDialog
Jared Lindblom06405c42013-01-17 20:48:39 -080052{
Alexander Afanasyev83a53002013-01-24 11:12:01 -080053 Q_OBJECT
Jared Lindblom06405c42013-01-17 20:48:39 -080054
Alexander Afanasyev83a53002013-01-24 11:12:01 -080055 public:
56 // constructor
57 explicit ChronoShareGui(QWidget* parent = 0);
58
59 // destructor
60 ~ChronoShareGui();
Jared Lindblomb4032e22013-01-17 23:50:51 -080061
Jared Lindblom06405c42013-01-17 20:48:39 -080062private slots:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080063 // open the shared folder
64 void openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -080065
Zhenkai Zhu25e13582013-02-27 15:33:01 -080066 void openFile();
67
68 void openInWebBrowser();
69
70 void updateRecentFilesMenu();
71
Alexander Afanasyev83a53002013-01-24 11:12:01 -080072 // open file dialog
73 void openFileDialog();
Jared Lindblomb4032e22013-01-17 23:50:51 -080074
Alexander Afanasyev83a53002013-01-24 11:12:01 -080075 // handle left click of tray icon
76 void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Jared Lindblom06405c42013-01-17 20:48:39 -080077
Alexander Afanasyev83a53002013-01-24 11:12:01 -080078 // view chronoshare settings
79 void viewSettings();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080080
Jared Lindblomc8ffd592013-01-25 00:00:30 -080081 // change chronoshare settings
82 void changeSettings();
83
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080084 // click on adhoc button
85 void onAdHocChange (bool state); // cannot be protected with #ifdef. otherwise something fishy with QT
Zhenkai Zhu249fbc72013-02-27 21:50:25 -080086
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080087 void onCheckForUpdates();
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080088
Jared Lindblom06405c42013-01-17 20:48:39 -080089private:
Zhenkai Zhu25e13582013-02-27 15:33:01 -080090 void checkFileAction(const std::string &, int, int);
Alexander Afanasyev83a53002013-01-24 11:12:01 -080091 // create actions that result from clicking a menu option
Zhenkai Zhu25e13582013-02-27 15:33:01 -080092 void createActionsAndMenu();
Jared Lindblom06405c42013-01-17 20:48:39 -080093
Alexander Afanasyev83a53002013-01-24 11:12:01 -080094 // create tray icon
95 void createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080096
Alexander Afanasyev83a53002013-01-24 11:12:01 -080097 // set icon image
98 void setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080099
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800100 // load persistent settings
101 bool loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800102
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800103 // save persistent settings
104 void saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800105
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800106 // prompt user dialog box
107 void openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800108
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800109 // overload
110 void openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800111
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800112 // capture close event
113 void closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -0800114
Alexander Afanasyevd437ffc2013-03-04 12:29:23 -0800115 // starts/restarts fs watcher and dispatcher
Zhenkai Zhud5756312013-01-31 13:49:45 -0800116 void
Alexander Afanasyevd437ffc2013-03-04 12:29:23 -0800117 startBackend(bool restart=false);
Zhenkai Zhud5756312013-01-31 13:49:45 -0800118
Jared Lindblom06405c42013-01-17 20:48:39 -0800119private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800120 QSystemTrayIcon* m_trayIcon; // tray icon
121 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -0800122
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800123 QAction* m_openFolder; // open the shared folder action
124 QAction* m_viewSettings; // chronoShare settings
125 QAction* m_changeFolder; // change the shared folder action
126 QAction* m_quitProgram; // quit program action
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800127 QAction *m_checkForUpdates;
Zhenkai Zhu25e13582013-02-27 15:33:01 -0800128 QAction *m_openWeb;
129 QMenu *m_recentFilesMenu;
130 QAction *m_fileActions[5];
Jared Lindblom06405c42013-01-17 20:48:39 -0800131
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800132 QAction *m_wifiAction;
133
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800134 QString m_dirPath; // shared directory
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800135 QString m_username; // username
136 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800137
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800138 FsWatcher *m_watcher;
139 Dispatcher *m_dispatcher;
Zhenkai Zhud9429222013-02-25 22:34:09 -0800140 http::server::server *m_httpServer;
141 boost::thread m_httpServerThread;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800142
143 QLabel* labelUsername;
144 QPushButton* button;
145 QLabel* labelSharedFolder;
146 QLabel* labelSharedFolderPath;
147 QLineEdit* editUsername;
148 QLineEdit* editSharedFolder;
149 QLineEdit* editSharedFolderPath;
150 QLabel *label;
151 QVBoxLayout *mainLayout;
152
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800153#ifdef ADHOC_SUPPORTED
154 Executor m_executor;
155#endif
156
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800157#ifdef SPARKLE_SUPPORTED
158 AutoUpdate *m_autoUpdate;
159#endif
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800160 // QString m_settingsFilePath; // settings file path
161 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800162};
163
164#endif // CHRONOSHAREGUI_H