blob: eba4c12e9eb0fdb2de35fe41c476f9ceda1e89f5 [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"
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080043
Jared Lindblomc8ffd592013-01-25 00:00:30 -080044class ChronoShareGui : public QDialog
Jared Lindblom06405c42013-01-17 20:48:39 -080045{
Alexander Afanasyev83a53002013-01-24 11:12:01 -080046 Q_OBJECT
Jared Lindblom06405c42013-01-17 20:48:39 -080047
Alexander Afanasyev83a53002013-01-24 11:12:01 -080048 public:
49 // constructor
50 explicit ChronoShareGui(QWidget* parent = 0);
51
52 // destructor
53 ~ChronoShareGui();
Jared Lindblomb4032e22013-01-17 23:50:51 -080054
Jared Lindblom06405c42013-01-17 20:48:39 -080055private slots:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080056 // open the shared folder
57 void openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -080058
Alexander Afanasyev83a53002013-01-24 11:12:01 -080059 // open file dialog
60 void openFileDialog();
Jared Lindblomb4032e22013-01-17 23:50:51 -080061
Alexander Afanasyev83a53002013-01-24 11:12:01 -080062 // handle left click of tray icon
63 void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Jared Lindblom06405c42013-01-17 20:48:39 -080064
Alexander Afanasyev83a53002013-01-24 11:12:01 -080065 // view chronoshare settings
66 void viewSettings();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080067
Jared Lindblomc8ffd592013-01-25 00:00:30 -080068 // change chronoshare settings
69 void changeSettings();
70
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080071 // click on adhoc button
72 void onAdHocChange (bool state); // cannot be protected with #ifdef. otherwise something fishy with QT
73
74
Jared Lindblom06405c42013-01-17 20:48:39 -080075private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080076 // create actions that result from clicking a menu option
77 void createActions();
Jared Lindblom06405c42013-01-17 20:48:39 -080078
Alexander Afanasyev83a53002013-01-24 11:12:01 -080079 // create tray icon
80 void createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080081
Alexander Afanasyev83a53002013-01-24 11:12:01 -080082 // set icon image
83 void setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080084
Alexander Afanasyev83a53002013-01-24 11:12:01 -080085 // load persistent settings
86 bool loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080087
Alexander Afanasyev83a53002013-01-24 11:12:01 -080088 // save persistent settings
89 void saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080090
Alexander Afanasyev83a53002013-01-24 11:12:01 -080091 // prompt user dialog box
92 void openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080093
Alexander Afanasyev83a53002013-01-24 11:12:01 -080094 // overload
95 void openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080096
Alexander Afanasyev83a53002013-01-24 11:12:01 -080097 // capture close event
98 void closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -080099
Zhenkai Zhud5756312013-01-31 13:49:45 -0800100 // starts fs watcher and dispatcher
101 void
102 startBackend();
103
Jared Lindblom06405c42013-01-17 20:48:39 -0800104private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800105 QSystemTrayIcon* m_trayIcon; // tray icon
106 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -0800107
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800108 QAction* m_openFolder; // open the shared folder action
109 QAction* m_viewSettings; // chronoShare settings
110 QAction* m_changeFolder; // change the shared folder action
111 QAction* m_quitProgram; // quit program action
Jared Lindblom06405c42013-01-17 20:48:39 -0800112
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800113 QAction *m_wifiAction;
114
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800115 QString m_dirPath; // shared directory
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800116 QString m_username; // username
117 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800118
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800119 FsWatcher *m_watcher;
120 Dispatcher *m_dispatcher;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800121
122 QLabel* labelUsername;
123 QPushButton* button;
124 QLabel* labelSharedFolder;
125 QLabel* labelSharedFolderPath;
126 QLineEdit* editUsername;
127 QLineEdit* editSharedFolder;
128 QLineEdit* editSharedFolderPath;
129 QLabel *label;
130 QVBoxLayout *mainLayout;
131
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800132#ifdef ADHOC_SUPPORTED
133 Executor m_executor;
134#endif
135
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800136 // QString m_settingsFilePath; // settings file path
137 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800138};
139
140#endif // CHRONOSHAREGUI_H