blob: 3e9e0c3d2ecbdc4af615108f4237a267f8eb55ad [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
Jared Lindblomc8ffd592013-01-25 00:00:30 -080028#include <QtGui>
Jared Lindblom06405c42013-01-17 20:48:39 -080029#include <QWidget>
30#include <QSystemTrayIcon>
31#include <QMenu>
Jared Lindblom06405c42013-01-17 20:48:39 -080032#include <QDebug>
33#include <QProcess>
Jared Lindblomb4032e22013-01-17 23:50:51 -080034#include <QSettings>
35#include <QDir>
36#include <QFileDialog>
37#include <QCloseEvent>
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080038#include <QMessageBox>
Jared Lindblom9d8a5b12013-01-20 15:21:17 -080039#include <QApplication>
Jared Lindblom06405c42013-01-17 20:48:39 -080040
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080041#include "fs-watcher.h"
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -080042#include "dispatcher.h"
Zhenkai Zhud9429222013-02-25 22:34:09 -080043#include "server.hpp"
44#include <boost/thread/thread.hpp>
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080045
Jared Lindblomc8ffd592013-01-25 00:00:30 -080046class ChronoShareGui : public QDialog
Jared Lindblom06405c42013-01-17 20:48:39 -080047{
Alexander Afanasyev83a53002013-01-24 11:12:01 -080048 Q_OBJECT
Jared Lindblom06405c42013-01-17 20:48:39 -080049
Alexander Afanasyev83a53002013-01-24 11:12:01 -080050 public:
51 // constructor
52 explicit ChronoShareGui(QWidget* parent = 0);
53
54 // destructor
55 ~ChronoShareGui();
Jared Lindblomb4032e22013-01-17 23:50:51 -080056
Jared Lindblom06405c42013-01-17 20:48:39 -080057private slots:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080058 // open the shared folder
59 void openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -080060
Alexander Afanasyev83a53002013-01-24 11:12:01 -080061 // open file dialog
62 void openFileDialog();
Jared Lindblomb4032e22013-01-17 23:50:51 -080063
Alexander Afanasyev83a53002013-01-24 11:12:01 -080064 // handle left click of tray icon
65 void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Jared Lindblom06405c42013-01-17 20:48:39 -080066
Alexander Afanasyev83a53002013-01-24 11:12:01 -080067 // view chronoshare settings
68 void viewSettings();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080069
Jared Lindblomc8ffd592013-01-25 00:00:30 -080070 // change chronoshare settings
71 void changeSettings();
72
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080073 // click on adhoc button
74 void onAdHocChange (bool state); // cannot be protected with #ifdef. otherwise something fishy with QT
75
76
Jared Lindblom06405c42013-01-17 20:48:39 -080077private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080078 // create actions that result from clicking a menu option
79 void createActions();
Jared Lindblom06405c42013-01-17 20:48:39 -080080
Alexander Afanasyev83a53002013-01-24 11:12:01 -080081 // create tray icon
82 void createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080083
Alexander Afanasyev83a53002013-01-24 11:12:01 -080084 // set icon image
85 void setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080086
Alexander Afanasyev83a53002013-01-24 11:12:01 -080087 // load persistent settings
88 bool loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080089
Alexander Afanasyev83a53002013-01-24 11:12:01 -080090 // save persistent settings
91 void saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080092
Alexander Afanasyev83a53002013-01-24 11:12:01 -080093 // prompt user dialog box
94 void openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080095
Alexander Afanasyev83a53002013-01-24 11:12:01 -080096 // overload
97 void openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080098
Alexander Afanasyev83a53002013-01-24 11:12:01 -080099 // capture close event
100 void closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -0800101
Zhenkai Zhud5756312013-01-31 13:49:45 -0800102 // starts fs watcher and dispatcher
103 void
104 startBackend();
105
Jared Lindblom06405c42013-01-17 20:48:39 -0800106private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800107 QSystemTrayIcon* m_trayIcon; // tray icon
108 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -0800109
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800110 QAction* m_openFolder; // open the shared folder action
111 QAction* m_viewSettings; // chronoShare settings
112 QAction* m_changeFolder; // change the shared folder action
113 QAction* m_quitProgram; // quit program action
Jared Lindblom06405c42013-01-17 20:48:39 -0800114
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800115 QAction *m_wifiAction;
116
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800117 QString m_dirPath; // shared directory
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800118 QString m_username; // username
119 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800120
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800121 FsWatcher *m_watcher;
122 Dispatcher *m_dispatcher;
Zhenkai Zhud9429222013-02-25 22:34:09 -0800123 http::server::server *m_httpServer;
124 boost::thread m_httpServerThread;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800125
126 QLabel* labelUsername;
127 QPushButton* button;
128 QLabel* labelSharedFolder;
129 QLabel* labelSharedFolderPath;
130 QLineEdit* editUsername;
131 QLineEdit* editSharedFolder;
132 QLineEdit* editSharedFolderPath;
133 QLabel *label;
134 QVBoxLayout *mainLayout;
135
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800136#ifdef ADHOC_SUPPORTED
137 Executor m_executor;
138#endif
139
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800140 // QString m_settingsFilePath; // settings file path
141 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800142};
143
144#endif // CHRONOSHAREGUI_H