blob: 23f6e9d750a56088aa95a5f3cb5e9da85b6c4e06 [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>
19 */
20
21#ifndef CHRONOSHAREGUI_H
22#define CHRONOSHAREGUI_H
23
Jared Lindblomc8ffd592013-01-25 00:00:30 -080024#include <QtGui>
Jared Lindblom06405c42013-01-17 20:48:39 -080025#include <QWidget>
26#include <QSystemTrayIcon>
27#include <QMenu>
Jared Lindblom06405c42013-01-17 20:48:39 -080028#include <QDebug>
29#include <QProcess>
Jared Lindblomb4032e22013-01-17 23:50:51 -080030#include <QSettings>
31#include <QDir>
32#include <QFileDialog>
33#include <QCloseEvent>
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080034#include <QMessageBox>
Jared Lindblom9d8a5b12013-01-20 15:21:17 -080035#include <QApplication>
Jared Lindblom06405c42013-01-17 20:48:39 -080036
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080037#include "fs-watcher.h"
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -080038#include "dispatcher.h"
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080039
Jared Lindblomc8ffd592013-01-25 00:00:30 -080040class ChronoShareGui : public QDialog
Jared Lindblom06405c42013-01-17 20:48:39 -080041{
Alexander Afanasyev83a53002013-01-24 11:12:01 -080042 Q_OBJECT
Jared Lindblom06405c42013-01-17 20:48:39 -080043
Alexander Afanasyev83a53002013-01-24 11:12:01 -080044 public:
45 // constructor
46 explicit ChronoShareGui(QWidget* parent = 0);
47
48 // destructor
49 ~ChronoShareGui();
Jared Lindblomb4032e22013-01-17 23:50:51 -080050
Jared Lindblom06405c42013-01-17 20:48:39 -080051private slots:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080052 // open the shared folder
53 void openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -080054
Alexander Afanasyev83a53002013-01-24 11:12:01 -080055 // open file dialog
56 void openFileDialog();
Jared Lindblomb4032e22013-01-17 23:50:51 -080057
Alexander Afanasyev83a53002013-01-24 11:12:01 -080058 // handle left click of tray icon
59 void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Jared Lindblom06405c42013-01-17 20:48:39 -080060
Alexander Afanasyev83a53002013-01-24 11:12:01 -080061 // view chronoshare settings
62 void viewSettings();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080063
Jared Lindblomc8ffd592013-01-25 00:00:30 -080064 // change chronoshare settings
65 void changeSettings();
66
Jared Lindblom06405c42013-01-17 20:48:39 -080067private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080068 // create actions that result from clicking a menu option
69 void createActions();
Jared Lindblom06405c42013-01-17 20:48:39 -080070
Alexander Afanasyev83a53002013-01-24 11:12:01 -080071 // create tray icon
72 void createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080073
Alexander Afanasyev83a53002013-01-24 11:12:01 -080074 // set icon image
75 void setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080076
Alexander Afanasyev83a53002013-01-24 11:12:01 -080077 // load persistent settings
78 bool loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080079
Alexander Afanasyev83a53002013-01-24 11:12:01 -080080 // save persistent settings
81 void saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080082
Alexander Afanasyev83a53002013-01-24 11:12:01 -080083 // prompt user dialog box
84 void openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080085
Alexander Afanasyev83a53002013-01-24 11:12:01 -080086 // overload
87 void openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080088
Alexander Afanasyev83a53002013-01-24 11:12:01 -080089 // capture close event
90 void closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -080091
Zhenkai Zhud5756312013-01-31 13:49:45 -080092 // starts fs watcher and dispatcher
93 void
94 startBackend();
95
Jared Lindblom06405c42013-01-17 20:48:39 -080096private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080097 QSystemTrayIcon* m_trayIcon; // tray icon
98 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -080099
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800100 QAction* m_openFolder; // open the shared folder action
101 QAction* m_viewSettings; // chronoShare settings
102 QAction* m_changeFolder; // change the shared folder action
103 QAction* m_quitProgram; // quit program action
Jared Lindblom06405c42013-01-17 20:48:39 -0800104
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800105 QString m_dirPath; // shared directory
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800106 QString m_username; // username
107 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800108
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800109 FsWatcher *m_watcher;
110 Dispatcher *m_dispatcher;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800111
112 QLabel* labelUsername;
113 QPushButton* button;
114 QLabel* labelSharedFolder;
115 QLabel* labelSharedFolderPath;
116 QLineEdit* editUsername;
117 QLineEdit* editSharedFolder;
118 QLineEdit* editSharedFolderPath;
119 QLabel *label;
120 QVBoxLayout *mainLayout;
121
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800122 // QString m_settingsFilePath; // settings file path
123 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800124};
125
126#endif // CHRONOSHAREGUI_H