blob: 6497d5fc362d73ef98cfd57afba573b019fb2b3f [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 Afanasyev85a4ba02013-02-24 16:30:17 -080026#include "adhoc.h"
27
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080028#if __APPLE__ && HAVE_SPARKLE
29#define SPARKLE_SUPPORTED 1
Zhenkai Zhubb170d42013-02-25 13:48:59 -080030#include "sparkle-auto-update.h"
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 Afanasyev9e5a4702013-01-24 13:15:23 -080046#include "fs-watcher.h"
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -080047#include "dispatcher.h"
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 Zhuaca6cb52013-02-24 23:34:03 -080086#ifdef SPARKLE_SUPPORTED
87 void onCheckForUpdates();
88#endif
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080089
Jared Lindblom06405c42013-01-17 20:48:39 -080090private:
Zhenkai Zhu25e13582013-02-27 15:33:01 -080091 void checkFileAction(const std::string &, int, int);
Alexander Afanasyev83a53002013-01-24 11:12:01 -080092 // create actions that result from clicking a menu option
Zhenkai Zhu25e13582013-02-27 15:33:01 -080093 void createActionsAndMenu();
Jared Lindblom06405c42013-01-17 20:48:39 -080094
Alexander Afanasyev83a53002013-01-24 11:12:01 -080095 // create tray icon
96 void createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080097
Alexander Afanasyev83a53002013-01-24 11:12:01 -080098 // set icon image
99 void setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -0800100
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800101 // load persistent settings
102 bool loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800103
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800104 // save persistent settings
105 void saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800106
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800107 // prompt user dialog box
108 void openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800109
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800110 // overload
111 void openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800112
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800113 // capture close event
114 void closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -0800115
Zhenkai Zhud5756312013-01-31 13:49:45 -0800116 // starts fs watcher and dispatcher
117 void
118 startBackend();
119
Jared Lindblom06405c42013-01-17 20:48:39 -0800120private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800121 QSystemTrayIcon* m_trayIcon; // tray icon
122 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -0800123
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800124 QAction* m_openFolder; // open the shared folder action
125 QAction* m_viewSettings; // chronoShare settings
126 QAction* m_changeFolder; // change the shared folder action
127 QAction* m_quitProgram; // quit program action
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800128 QAction *m_checkForUpdates;
Zhenkai Zhu25e13582013-02-27 15:33:01 -0800129 QAction *m_openWeb;
130 QMenu *m_recentFilesMenu;
131 QAction *m_fileActions[5];
Jared Lindblom06405c42013-01-17 20:48:39 -0800132
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800133 QAction *m_wifiAction;
134
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800135 QString m_dirPath; // shared directory
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800136 QString m_username; // username
137 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800138
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800139 FsWatcher *m_watcher;
140 Dispatcher *m_dispatcher;
Zhenkai Zhud9429222013-02-25 22:34:09 -0800141 http::server::server *m_httpServer;
142 boost::thread m_httpServerThread;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800143
144 QLabel* labelUsername;
145 QPushButton* button;
146 QLabel* labelSharedFolder;
147 QLabel* labelSharedFolderPath;
148 QLineEdit* editUsername;
149 QLineEdit* editSharedFolder;
150 QLineEdit* editSharedFolderPath;
151 QLabel *label;
152 QVBoxLayout *mainLayout;
153
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800154#ifdef ADHOC_SUPPORTED
155 Executor m_executor;
156#endif
157
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800158#ifdef SPARKLE_SUPPORTED
159 AutoUpdate *m_autoUpdate;
160#endif
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800161 // QString m_settingsFilePath; // settings file path
162 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800163};
164
165#endif // CHRONOSHAREGUI_H