blob: 8d811e873d76c812fe8a2790a78226a01b18b0d4 [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>
21 * Ilya Moiseenko <iliamo@ucla.edu>
Jared Lindblom06405c42013-01-17 20:48:39 -080022 */
23
24#include "chronosharegui.h"
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080025
Alexander Afanasyev83a53002013-01-24 11:12:01 -080026#include "logging.h"
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -080027#include "ccnx-wrapper.h"
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080028#include <QValidator>
Zhenkai Zhuce04cb42013-02-25 15:29:31 -080029#include <QDir>
30#include <QDesktopServices>
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -080031
32#include <boost/make_shared.hpp>
33
34using namespace boost;
35using namespace Ccnx;
Jared Lindblom06405c42013-01-17 20:48:39 -080036
Zhenkai Zhud9429222013-02-25 22:34:09 -080037static const string HTTP_SERVER_ADDRESS = "localhost";
38static const string HTTP_SERVER_PORT = "9001";
39static const string DOC_ROOT = ":/html";
40static const QString ICON_PICTURE_QSTRING(":/images/friends-group-icon.png");
41
Alexander Afanasyev83a53002013-01-24 11:12:01 -080042INIT_LOGGER ("Gui");
43
44ChronoShareGui::ChronoShareGui(QWidget *parent)
Jared Lindblomc8ffd592013-01-25 00:00:30 -080045 : QDialog(parent)
Zhenkai Zhud5756312013-01-31 13:49:45 -080046 , m_watcher(0)
47 , m_dispatcher(0)
Zhenkai Zhud9429222013-02-25 22:34:09 -080048 , m_httpServer(0)
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080049#ifdef ADHOC_SUPPORTED
50 , m_executor (1)
51#endif
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080052#ifdef SPARKLE_SUPPORTED
Zhenkai Zhubb170d42013-02-25 13:48:59 -080053 , m_autoUpdate(new SparkleAutoUpdate(tr("http://no-url.org")))
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080054#endif
Jared Lindblom06405c42013-01-17 20:48:39 -080055{
Jared Lindblomf4b900e2013-02-07 18:08:47 -080056 setWindowTitle("Settings");
Jared Lindblomc8ffd592013-01-25 00:00:30 -080057
Jared Lindblomd8b76ad2013-02-07 20:37:37 -080058 labelUsername = new QLabel("Username (hint: /<username>)");
Jared Lindblomc8ffd592013-01-25 00:00:30 -080059 labelSharedFolder = new QLabel("Shared Folder Name");
60 labelSharedFolderPath = new QLabel("Shared Folder Path");
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080061
Zhenkai Zhud5756312013-01-31 13:49:45 -080062 QRegExp regex("(/[^/]+)+$");
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080063 QValidator *prefixValidator = new QRegExpValidator(regex, this);
64
Jared Lindblomc8ffd592013-01-25 00:00:30 -080065 editUsername = new QLineEdit();
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080066 editUsername->setValidator(prefixValidator);
67
68 QRegExp noPureWhiteSpace("^\\S+.*$");
69 QValidator *wsValidator = new QRegExpValidator(noPureWhiteSpace, this);
Jared Lindblomc8ffd592013-01-25 00:00:30 -080070 editSharedFolder = new QLineEdit();
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080071 editSharedFolder->setValidator(wsValidator);
72
Jared Lindblomc8ffd592013-01-25 00:00:30 -080073 editSharedFolderPath = new QLineEdit();
74 editSharedFolderPath->setReadOnly(true);
75 QPalette pal = editSharedFolderPath->palette();
76 pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Disabled, QPalette::Base));
77 editSharedFolderPath->setPalette(pal);
78 button = new QPushButton("Submit");
79 label = new QLabel();
80
81 connect(button, SIGNAL(clicked()), this, SLOT(changeSettings()));
82
83 mainLayout = new QVBoxLayout; //vertically
84 mainLayout->addWidget(labelUsername);
85 mainLayout->addWidget(editUsername);
86 mainLayout->addWidget(labelSharedFolder);
87 mainLayout->addWidget(editSharedFolder);
88 mainLayout->addWidget(labelSharedFolderPath);
89 mainLayout->addWidget(editSharedFolderPath);
90 mainLayout->addWidget(button);
91 mainLayout->addWidget(label);
92 setLayout(mainLayout);
93
Alexander Afanasyev83a53002013-01-24 11:12:01 -080094 // create actions that result from clicking a menu option
95 createActions();
Jared Lindblomb4032e22013-01-17 23:50:51 -080096
Alexander Afanasyev83a53002013-01-24 11:12:01 -080097 // create tray icon
98 createTrayIcon();
Jared Lindblomb4032e22013-01-17 23:50:51 -080099
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800100 // set icon image
101 setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -0800102
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800103 // show tray icon
104 m_trayIcon->show();
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800105
106 // Dispatcher(const boost::filesystem::path &path, const std::string &localUserName, const Ccnx::Name &localPrefix,
107 // const std::string &sharedFolder, const boost::filesystem::path &rootDir,
108 // Ccnx::CcnxWrapperPtr ccnx, SchedulerPtr scheduler, int poolSize = 2);
109
Zhenkai Zhud5756312013-01-31 13:49:45 -0800110 // load settings
111 if(!loadSettings())
112 {
113 // prompt user to choose folder
114 openMessageBox("First Time Setup", "Please enter a username, shared folder name and choose the shared folder path on your local filesystem.");
115 viewSettings();
116 openFileDialog();
117 viewSettings();
118 }
119 else
120 {
121 startBackend();
122 }
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800123
124#ifdef ADHOC_SUPPORTED
125 m_executor.start ();
126#endif
Zhenkai Zhud5756312013-01-31 13:49:45 -0800127}
128
129void
130ChronoShareGui::startBackend()
131{
132 if (m_watcher != 0 && m_dispatcher != 0)
133 {
134 return;
135 }
136
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800137 m_dispatcher = new Dispatcher (m_username.toStdString (), m_sharedFolderName.toStdString (),
138 m_dirPath.toStdString (), make_shared<CcnxWrapper> ());
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800139
140 // Alex: this **must** be here, otherwise m_dirPath will be uninitialized
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800141 m_watcher = new FsWatcher (m_dirPath,
142 bind (&Dispatcher::Did_LocalFile_AddOrModify, m_dispatcher, _1),
Zhenkai Zhud1756272013-02-01 17:02:18 -0800143 bind (&Dispatcher::Did_LocalFile_Delete, m_dispatcher, _1));
Zhenkai Zhud9429222013-02-25 22:34:09 -0800144 QFileInfo indexHtmlInfo(":/html/index.html");
145 if (indexHtmlInfo.exists())
146 {
147 m_httpServer = new http::server::server(HTTP_SERVER_ADDRESS, HTTP_SERVER_PORT, DOC_ROOT);
148 m_httpServerThread = boost::thread(&http::server::server::run, m_httpServer);
149 }
150 else
151 {
152 _LOG_ERROR ("Http server doc root dir does not exist!");
153 // shall we bail here?
154 }
Jared Lindblom06405c42013-01-17 20:48:39 -0800155}
156
157ChronoShareGui::~ChronoShareGui()
158{
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800159#ifdef ADHOC_SUPPORTED
160 m_executor.shutdown ();
161#endif
162
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800163 delete m_watcher; // stop filewatching ASAP
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800164 delete m_dispatcher; // stop dispatcher ASAP, but after watcher (to prevent triggering callbacks on deleted object)
Zhenkai Zhud9429222013-02-25 22:34:09 -0800165 delete m_httpServer;
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800166
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800167 // cleanup
168 delete m_trayIcon;
169 delete m_trayIconMenu;
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800170#ifdef ADHOC_SUPPORTED
171 delete m_wifiAction;
172#endif
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800173#ifdef SPARKLE_SUPPORTED
174 delete m_autoUpdate;
Zhenkai Zhubb170d42013-02-25 13:48:59 -0800175 delete m_checkForUpdates;
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800176#endif
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800177 delete m_openFolder;
178 delete m_viewSettings;
179 delete m_changeFolder;
180 delete m_quitProgram;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800181
182 delete labelUsername;
183 delete labelSharedFolder;
184 delete editUsername;
185 delete editSharedFolder;
186 delete button;
187 delete label;
188 delete mainLayout;
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800189}
190
191void ChronoShareGui::openMessageBox(QString title, QString text)
192{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800193 QMessageBox messageBox(this);
194 messageBox.setWindowTitle(title);
195 messageBox.setText(text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800196
Zhenkai Zhud9429222013-02-25 22:34:09 -0800197 messageBox.setIconPixmap(QPixmap(ICON_PICTURE_QSTRING));
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800198
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800199 messageBox.exec();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800200}
201
202void ChronoShareGui::openMessageBox(QString title, QString text, QString infotext)
203{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800204 QMessageBox messageBox(this);
205 messageBox.setWindowTitle(title);
206 messageBox.setText(text);
207 messageBox.setInformativeText(infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800208
Zhenkai Zhud9429222013-02-25 22:34:09 -0800209 messageBox.setIconPixmap(QPixmap(ICON_PICTURE_QSTRING));
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800210
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800211 messageBox.exec();
Jared Lindblom06405c42013-01-17 20:48:39 -0800212}
213
214void ChronoShareGui::createActions()
215{
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800216 _LOG_DEBUG ("Create actions");
217
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800218 // create the "open folder" action
219 m_openFolder = new QAction(tr("&Open Folder"), this);
220 connect(m_openFolder, SIGNAL(triggered()), this, SLOT(openSharedFolder()));
Jared Lindblom06405c42013-01-17 20:48:39 -0800221
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800222 // create the "view settings" action
223 m_viewSettings = new QAction(tr("&View Settings"), this);
224 connect(m_viewSettings, SIGNAL(triggered()), this, SLOT(viewSettings()));
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800225
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800226 // create the "change folder" action
227 m_changeFolder = new QAction(tr("&Change Folder"), this);
228 connect(m_changeFolder, SIGNAL(triggered()), this, SLOT(openFileDialog()));
Jared Lindblomb4032e22013-01-17 23:50:51 -0800229
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800230#ifdef ADHOC_SUPPORTED
231 // create "AdHoc Wifi" action
232 m_wifiAction = new QAction (tr("Enable AdHoc &WiFI"), m_trayIconMenu);
233 m_wifiAction->setChecked (false);
234 m_wifiAction->setCheckable (true);
235 connect (m_wifiAction, SIGNAL (toggled(bool)), this, SLOT(onAdHocChange(bool)));
236#endif
237
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800238#ifdef SPARKLE_SUPPORTED
Zhenkai Zhubb170d42013-02-25 13:48:59 -0800239 m_checkForUpdates = new QAction (tr("Check For Updates"), this);
240 connect (m_checkForUpdates, SIGNAL(triggered()), this, SLOT(onCheckForUpdates()));
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800241#endif
242
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800243 // create the "quit program" action
244 m_quitProgram = new QAction(tr("&Quit"), this);
245 connect(m_quitProgram, SIGNAL(triggered()), qApp, SLOT(quit()));
Jared Lindblom06405c42013-01-17 20:48:39 -0800246}
247
248void ChronoShareGui::createTrayIcon()
249{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800250 // create a new icon menu
251 m_trayIconMenu = new QMenu(this);
Jared Lindblom06405c42013-01-17 20:48:39 -0800252
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800253 // add actions to the menu
254 m_trayIconMenu->addAction(m_openFolder);
255 m_trayIconMenu->addSeparator();
256 m_trayIconMenu->addAction(m_viewSettings);
257 m_trayIconMenu->addAction(m_changeFolder);
258 m_trayIconMenu->addSeparator();
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800259 m_trayIconMenu->addAction(m_wifiAction);
260 m_trayIconMenu->addSeparator();
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800261 m_trayIconMenu->addAction(m_quitProgram);
Jared Lindblom06405c42013-01-17 20:48:39 -0800262
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800263 // create new tray icon
264 m_trayIcon = new QSystemTrayIcon(this);
Jared Lindblomb4032e22013-01-17 23:50:51 -0800265
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800266#ifdef ADHOC_SUPPORTED
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800267 // associate the menu with the tray icon
268 m_trayIcon->setContextMenu(m_trayIconMenu);
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800269#endif
Jared Lindblomb4032e22013-01-17 23:50:51 -0800270
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800271 // handle left click of icon
272 connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
Jared Lindblom06405c42013-01-17 20:48:39 -0800273}
274
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800275void
276ChronoShareGui::onAdHocChange (bool state)
277{
278#ifdef ADHOC_SUPPORTED
279 if (m_wifiAction->isChecked ())
280 {
281 QMessageBox msgBox;
282 msgBox.setText ("WARNING: your WiFi will be disconnected");
283 msgBox.setIcon (QMessageBox::Warning);
284 msgBox.setInformativeText("AdHoc WiFi will disconnect your current WiFi.\n Are you sure that you are OK with that?");
285 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
286 msgBox.setDefaultButton(QMessageBox::Cancel);
287 int ret = msgBox.exec();
288
289 if (ret == QMessageBox::Cancel)
290 {
291 m_wifiAction->setChecked (false);
292 }
293 else
294 {
295
296 m_wifiAction->setText (tr("Disable AdHoc WiFI"));
297
298 // create adhoc
299 m_executor.execute (Adhoc::CreateAdhoc);
300 }
301 }
302 else
303 {
304 m_wifiAction->setText (tr("Enable AdHoc WiFI"));
305
306 // disable adhoc
307 m_executor.execute (Adhoc::DestroyAdhoc);
308
309 // a trick in DestroyAdhoc ensures that WiFi will be reconnected to a default WiFi
310 }
311#endif
312}
313
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800314#ifdef SPARKLE_SUPPORTED
315void
316ChronoShareGui::onCheckForUpdates()
317{
318 m_autoUpdate->checkForUpdates();
319}
320#endif
321
Jared Lindblom06405c42013-01-17 20:48:39 -0800322void ChronoShareGui::setIcon()
323{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800324 // set the icon image
Zhenkai Zhud9429222013-02-25 22:34:09 -0800325 m_trayIcon->setIcon(QIcon(ICON_PICTURE_QSTRING));
Jared Lindblom06405c42013-01-17 20:48:39 -0800326}
327
328void ChronoShareGui::openSharedFolder()
329{
Zhenkai Zhuce04cb42013-02-25 15:29:31 -0800330 QString path = QDir::toNativeSeparators(m_dirPath);
331 QDesktopServices::openUrl(QUrl("file:///" + path));
Jared Lindblom06405c42013-01-17 20:48:39 -0800332}
Jared Lindblomb4032e22013-01-17 23:50:51 -0800333
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800334void ChronoShareGui::changeSettings()
335{
336 if(!editUsername->text().isEmpty())
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -0800337 m_username = editUsername->text().trimmed();
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800338 else
339 editUsername->setText(m_username);
340
341 if(!editSharedFolder->text().isEmpty())
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -0800342 m_sharedFolderName = editSharedFolder->text().trimmed();
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800343 else
344 editSharedFolder->setText(m_sharedFolderName);
345
346 saveSettings();
347 this->hide();
Zhenkai Zhud5756312013-01-31 13:49:45 -0800348
349 startBackend();
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800350}
351
Jared Lindblomb4032e22013-01-17 23:50:51 -0800352void ChronoShareGui::openFileDialog()
353{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800354 // prompt user for new directory
355 QString tempPath = QFileDialog::getExistingDirectory(this, tr("Choose a new folder"),
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800356 m_dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
357 QFileInfo qFileInfo (tempPath);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800358
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800359 if(qFileInfo.isDir())
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800360 {
361 m_dirPath = tempPath;
362 editSharedFolderPath->setText(m_dirPath);
363 }
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800364 else
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800365 {
366 openMessageBox ("Error", "Not a valid folder, Ignoring.");
367 }
Jared Lindblomb4032e22013-01-17 23:50:51 -0800368
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800369 _LOG_DEBUG ("Selected path: " << m_dirPath.toStdString ());
Jared Lindblomb4032e22013-01-17 23:50:51 -0800370
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800371 // save settings
372 saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800373}
374
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800375void ChronoShareGui::trayIconClicked (QSystemTrayIcon::ActivationReason reason)
Jared Lindblomb4032e22013-01-17 23:50:51 -0800376{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800377 // if double clicked, open shared folder
378 if(reason == QSystemTrayIcon::DoubleClick)
Jared Lindblomb4032e22013-01-17 23:50:51 -0800379 {
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800380 openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800381 }
382}
383
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800384void ChronoShareGui::viewSettings()
Jared Lindblomb4032e22013-01-17 23:50:51 -0800385{
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800386 //simple for now
387 this->show();
Zhenkai Zhud5756312013-01-31 13:49:45 -0800388 this->raise();
389 this->activateWindow();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800390}
391
392bool ChronoShareGui::loadSettings()
393{
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800394 bool successful = true;
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800395
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800396 // Load Settings
397 // QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
398 QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800399
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800400 // _LOG_DEBUG (lexical_cast<string> (settings.allKeys()));
401
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800402 if(settings.contains("username"))
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800403 {
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800404 m_username = settings.value("username", "admin").toString();
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800405 }
406 else
407 {
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800408 successful = false;
409 }
410
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800411 editUsername->setText(m_username);
412
413 if(settings.contains("sharedfoldername"))
414 {
415 m_sharedFolderName = settings.value("sharedfoldername", "shared").toString();
416 }
417 else
418 {
419 successful = false;
420 }
421
422 editSharedFolder->setText(m_sharedFolderName);
423
424 if(settings.contains("dirPath"))
425 {
426 m_dirPath = settings.value("dirPath", QDir::homePath()).toString();
427 }
428 else
429 {
430 successful = false;
431 }
432
433 editSharedFolderPath->setText(m_dirPath);
434
435 _LOG_DEBUG ("Found configured path: " << (successful ? m_dirPath.toStdString () : std::string("no")));
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800436
437 return successful;
Jared Lindblomb4032e22013-01-17 23:50:51 -0800438}
439
440void ChronoShareGui::saveSettings()
441{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800442 // Save Settings
443 // QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
444 QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800445
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800446 settings.setValue("dirPath", m_dirPath);
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800447 settings.setValue("username", m_username);
448 settings.setValue("sharedfoldername", m_sharedFolderName);
Jared Lindblomb4032e22013-01-17 23:50:51 -0800449}
450
451void ChronoShareGui::closeEvent(QCloseEvent* event)
452{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800453 _LOG_DEBUG ("Close Event")
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800454 this->hide();
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800455 event->ignore(); // don't let the event propagate to the base class
Jared Lindblomb4032e22013-01-17 23:50:51 -0800456}
Jared Lindblomdc845f02013-01-18 17:29:40 -0800457
458#if WAF
459#include "chronosharegui.moc"
460#include "chronosharegui.cpp.moc"
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800461#endif