blob: e0db4ba2feaf2812316a715f5f00f9575c41a0d6 [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"
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080048
Jared Lindblomc8ffd592013-01-25 00:00:30 -080049class ChronoShareGui : public QDialog
Jared Lindblom06405c42013-01-17 20:48:39 -080050{
Alexander Afanasyev83a53002013-01-24 11:12:01 -080051 Q_OBJECT
Jared Lindblom06405c42013-01-17 20:48:39 -080052
Alexander Afanasyev83a53002013-01-24 11:12:01 -080053 public:
54 // constructor
55 explicit ChronoShareGui(QWidget* parent = 0);
56
57 // destructor
58 ~ChronoShareGui();
Jared Lindblomb4032e22013-01-17 23:50:51 -080059
Jared Lindblom06405c42013-01-17 20:48:39 -080060private slots:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080061 // open the shared folder
62 void openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -080063
Alexander Afanasyev83a53002013-01-24 11:12:01 -080064 // open file dialog
65 void openFileDialog();
Jared Lindblomb4032e22013-01-17 23:50:51 -080066
Alexander Afanasyev83a53002013-01-24 11:12:01 -080067 // handle left click of tray icon
68 void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Jared Lindblom06405c42013-01-17 20:48:39 -080069
Alexander Afanasyev83a53002013-01-24 11:12:01 -080070 // view chronoshare settings
71 void viewSettings();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -080072
Jared Lindblomc8ffd592013-01-25 00:00:30 -080073 // change chronoshare settings
74 void changeSettings();
75
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080076 // click on adhoc button
77 void onAdHocChange (bool state); // cannot be protected with #ifdef. otherwise something fishy with QT
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080078#ifdef SPARKLE_SUPPORTED
79 void onCheckForUpdates();
80#endif
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080081
Jared Lindblom06405c42013-01-17 20:48:39 -080082private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -080083 // create actions that result from clicking a menu option
84 void createActions();
Jared Lindblom06405c42013-01-17 20:48:39 -080085
Alexander Afanasyev83a53002013-01-24 11:12:01 -080086 // create tray icon
87 void createTrayIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080088
Alexander Afanasyev83a53002013-01-24 11:12:01 -080089 // set icon image
90 void setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080091
Alexander Afanasyev83a53002013-01-24 11:12:01 -080092 // load persistent settings
93 bool loadSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080094
Alexander Afanasyev83a53002013-01-24 11:12:01 -080095 // save persistent settings
96 void saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -080097
Alexander Afanasyev83a53002013-01-24 11:12:01 -080098 // prompt user dialog box
99 void openMessageBox(QString title, QString text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800100
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800101 // overload
102 void openMessageBox(QString title, QString text, QString infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800103
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800104 // capture close event
105 void closeEvent(QCloseEvent* event);
Jared Lindblom06405c42013-01-17 20:48:39 -0800106
Zhenkai Zhud5756312013-01-31 13:49:45 -0800107 // starts fs watcher and dispatcher
108 void
109 startBackend();
110
Jared Lindblom06405c42013-01-17 20:48:39 -0800111private:
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800112 QSystemTrayIcon* m_trayIcon; // tray icon
113 QMenu* m_trayIconMenu; // tray icon menu
Jared Lindblom06405c42013-01-17 20:48:39 -0800114
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800115 QAction* m_openFolder; // open the shared folder action
116 QAction* m_viewSettings; // chronoShare settings
117 QAction* m_changeFolder; // change the shared folder action
118 QAction* m_quitProgram; // quit program action
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800119 QAction *m_checkForUpdates;
Jared Lindblom06405c42013-01-17 20:48:39 -0800120
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800121 QAction *m_wifiAction;
122
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800123 QString m_dirPath; // shared directory
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800124 QString m_username; // username
125 QString m_sharedFolderName; // shared folder name
Jared Lindblomb4032e22013-01-17 23:50:51 -0800126
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800127 FsWatcher *m_watcher;
128 Dispatcher *m_dispatcher;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800129
130 QLabel* labelUsername;
131 QPushButton* button;
132 QLabel* labelSharedFolder;
133 QLabel* labelSharedFolderPath;
134 QLineEdit* editUsername;
135 QLineEdit* editSharedFolder;
136 QLineEdit* editSharedFolderPath;
137 QLabel *label;
138 QVBoxLayout *mainLayout;
139
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800140#ifdef ADHOC_SUPPORTED
141 Executor m_executor;
142#endif
143
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800144#ifdef SPARKLE_SUPPORTED
145 AutoUpdate *m_autoUpdate;
146#endif
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800147 // QString m_settingsFilePath; // settings file path
148 // QString m_settings;
Jared Lindblom06405c42013-01-17 20:48:39 -0800149};
150
151#endif // CHRONOSHAREGUI_H