blob: d37b98510e700219c2b1625d6ab3ae150b226415 [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>
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -080029
30#include <boost/make_shared.hpp>
31
32using namespace boost;
33using namespace Ccnx;
Jared Lindblom06405c42013-01-17 20:48:39 -080034
Alexander Afanasyev83a53002013-01-24 11:12:01 -080035INIT_LOGGER ("Gui");
36
37ChronoShareGui::ChronoShareGui(QWidget *parent)
Jared Lindblomc8ffd592013-01-25 00:00:30 -080038 : QDialog(parent)
Zhenkai Zhud5756312013-01-31 13:49:45 -080039 , m_watcher(0)
40 , m_dispatcher(0)
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -080041#ifdef ADHOC_SUPPORTED
42 , m_executor (1)
43#endif
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080044#ifdef SPARKLE_SUPPORTED
45 , m_autoUpdate(0)
46#endif
Jared Lindblom06405c42013-01-17 20:48:39 -080047{
Jared Lindblomf4b900e2013-02-07 18:08:47 -080048 setWindowTitle("Settings");
Jared Lindblomc8ffd592013-01-25 00:00:30 -080049
Jared Lindblomd8b76ad2013-02-07 20:37:37 -080050 labelUsername = new QLabel("Username (hint: /<username>)");
Jared Lindblomc8ffd592013-01-25 00:00:30 -080051 labelSharedFolder = new QLabel("Shared Folder Name");
52 labelSharedFolderPath = new QLabel("Shared Folder Path");
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080053
Zhenkai Zhud5756312013-01-31 13:49:45 -080054 QRegExp regex("(/[^/]+)+$");
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080055 QValidator *prefixValidator = new QRegExpValidator(regex, this);
56
Jared Lindblomc8ffd592013-01-25 00:00:30 -080057 editUsername = new QLineEdit();
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080058 editUsername->setValidator(prefixValidator);
59
60 QRegExp noPureWhiteSpace("^\\S+.*$");
61 QValidator *wsValidator = new QRegExpValidator(noPureWhiteSpace, this);
Jared Lindblomc8ffd592013-01-25 00:00:30 -080062 editSharedFolder = new QLineEdit();
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -080063 editSharedFolder->setValidator(wsValidator);
64
Jared Lindblomc8ffd592013-01-25 00:00:30 -080065 editSharedFolderPath = new QLineEdit();
66 editSharedFolderPath->setReadOnly(true);
67 QPalette pal = editSharedFolderPath->palette();
68 pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Disabled, QPalette::Base));
69 editSharedFolderPath->setPalette(pal);
70 button = new QPushButton("Submit");
71 label = new QLabel();
72
73 connect(button, SIGNAL(clicked()), this, SLOT(changeSettings()));
74
75 mainLayout = new QVBoxLayout; //vertically
76 mainLayout->addWidget(labelUsername);
77 mainLayout->addWidget(editUsername);
78 mainLayout->addWidget(labelSharedFolder);
79 mainLayout->addWidget(editSharedFolder);
80 mainLayout->addWidget(labelSharedFolderPath);
81 mainLayout->addWidget(editSharedFolderPath);
82 mainLayout->addWidget(button);
83 mainLayout->addWidget(label);
84 setLayout(mainLayout);
85
Alexander Afanasyev83a53002013-01-24 11:12:01 -080086 // create actions that result from clicking a menu option
87 createActions();
Jared Lindblomb4032e22013-01-17 23:50:51 -080088
Alexander Afanasyev83a53002013-01-24 11:12:01 -080089 // create tray icon
90 createTrayIcon();
Jared Lindblomb4032e22013-01-17 23:50:51 -080091
Alexander Afanasyev83a53002013-01-24 11:12:01 -080092 // set icon image
93 setIcon();
Jared Lindblom06405c42013-01-17 20:48:39 -080094
Alexander Afanasyev83a53002013-01-24 11:12:01 -080095 // show tray icon
96 m_trayIcon->show();
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080097
98 // Dispatcher(const boost::filesystem::path &path, const std::string &localUserName, const Ccnx::Name &localPrefix,
99 // const std::string &sharedFolder, const boost::filesystem::path &rootDir,
100 // Ccnx::CcnxWrapperPtr ccnx, SchedulerPtr scheduler, int poolSize = 2);
101
Zhenkai Zhud5756312013-01-31 13:49:45 -0800102 // load settings
103 if(!loadSettings())
104 {
105 // prompt user to choose folder
106 openMessageBox("First Time Setup", "Please enter a username, shared folder name and choose the shared folder path on your local filesystem.");
107 viewSettings();
108 openFileDialog();
109 viewSettings();
110 }
111 else
112 {
113 startBackend();
114 }
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800115
116#ifdef ADHOC_SUPPORTED
117 m_executor.start ();
118#endif
Zhenkai Zhud5756312013-01-31 13:49:45 -0800119}
120
121void
122ChronoShareGui::startBackend()
123{
124 if (m_watcher != 0 && m_dispatcher != 0)
125 {
126 return;
127 }
128
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800129 m_dispatcher = new Dispatcher (m_username.toStdString (), m_sharedFolderName.toStdString (),
130 m_dirPath.toStdString (), make_shared<CcnxWrapper> ());
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800131
132 // Alex: this **must** be here, otherwise m_dirPath will be uninitialized
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800133 m_watcher = new FsWatcher (m_dirPath,
134 bind (&Dispatcher::Did_LocalFile_AddOrModify, m_dispatcher, _1),
Zhenkai Zhud1756272013-02-01 17:02:18 -0800135 bind (&Dispatcher::Did_LocalFile_Delete, m_dispatcher, _1));
Jared Lindblom06405c42013-01-17 20:48:39 -0800136}
137
138ChronoShareGui::~ChronoShareGui()
139{
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800140#ifdef ADHOC_SUPPORTED
141 m_executor.shutdown ();
142#endif
143
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800144 delete m_watcher; // stop filewatching ASAP
Alexander Afanasyev9ca444e2013-01-25 16:29:35 -0800145 delete m_dispatcher; // stop dispatcher ASAP, but after watcher (to prevent triggering callbacks on deleted object)
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800146
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800147 // cleanup
148 delete m_trayIcon;
149 delete m_trayIconMenu;
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800150#ifdef ADHOC_SUPPORTED
151 delete m_wifiAction;
152#endif
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800153#ifdef SPARKLE_SUPPORTED
154 delete m_autoUpdate;
155#endif
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800156 delete m_openFolder;
157 delete m_viewSettings;
158 delete m_changeFolder;
159 delete m_quitProgram;
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800160
161 delete labelUsername;
162 delete labelSharedFolder;
163 delete editUsername;
164 delete editSharedFolder;
165 delete button;
166 delete label;
167 delete mainLayout;
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800168}
169
170void ChronoShareGui::openMessageBox(QString title, QString text)
171{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800172 QMessageBox messageBox(this);
173 messageBox.setWindowTitle(title);
174 messageBox.setText(text);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800175
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800176 messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800177
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800178 messageBox.exec();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800179}
180
181void ChronoShareGui::openMessageBox(QString title, QString text, QString infotext)
182{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800183 QMessageBox messageBox(this);
184 messageBox.setWindowTitle(title);
185 messageBox.setText(text);
186 messageBox.setInformativeText(infotext);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800187
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800188 messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800189
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800190 messageBox.exec();
Jared Lindblom06405c42013-01-17 20:48:39 -0800191}
192
193void ChronoShareGui::createActions()
194{
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800195 _LOG_DEBUG ("Create actions");
196
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800197 // create the "open folder" action
198 m_openFolder = new QAction(tr("&Open Folder"), this);
199 connect(m_openFolder, SIGNAL(triggered()), this, SLOT(openSharedFolder()));
Jared Lindblom06405c42013-01-17 20:48:39 -0800200
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800201 // create the "view settings" action
202 m_viewSettings = new QAction(tr("&View Settings"), this);
203 connect(m_viewSettings, SIGNAL(triggered()), this, SLOT(viewSettings()));
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800204
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800205 // create the "change folder" action
206 m_changeFolder = new QAction(tr("&Change Folder"), this);
207 connect(m_changeFolder, SIGNAL(triggered()), this, SLOT(openFileDialog()));
Jared Lindblomb4032e22013-01-17 23:50:51 -0800208
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800209#ifdef ADHOC_SUPPORTED
210 // create "AdHoc Wifi" action
211 m_wifiAction = new QAction (tr("Enable AdHoc &WiFI"), m_trayIconMenu);
212 m_wifiAction->setChecked (false);
213 m_wifiAction->setCheckable (true);
214 connect (m_wifiAction, SIGNAL (toggled(bool)), this, SLOT(onAdHocChange(bool)));
215#endif
216
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800217#ifdef SPARKLE_SUPPORTED
218 m_autoUpdate = new QAction (tr("Check For Updates"), this);
219 connect (m_autoUpdate, SIGNAL(triggered()), this, SLOT(onCheckForUpdates()));
220#endif
221
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800222 // create the "quit program" action
223 m_quitProgram = new QAction(tr("&Quit"), this);
224 connect(m_quitProgram, SIGNAL(triggered()), qApp, SLOT(quit()));
Jared Lindblom06405c42013-01-17 20:48:39 -0800225}
226
227void ChronoShareGui::createTrayIcon()
228{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800229 // create a new icon menu
230 m_trayIconMenu = new QMenu(this);
Jared Lindblom06405c42013-01-17 20:48:39 -0800231
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800232 // add actions to the menu
233 m_trayIconMenu->addAction(m_openFolder);
234 m_trayIconMenu->addSeparator();
235 m_trayIconMenu->addAction(m_viewSettings);
236 m_trayIconMenu->addAction(m_changeFolder);
237 m_trayIconMenu->addSeparator();
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800238 m_trayIconMenu->addAction(m_wifiAction);
239 m_trayIconMenu->addSeparator();
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800240 m_trayIconMenu->addAction(m_quitProgram);
Jared Lindblom06405c42013-01-17 20:48:39 -0800241
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800242 // create new tray icon
243 m_trayIcon = new QSystemTrayIcon(this);
Jared Lindblomb4032e22013-01-17 23:50:51 -0800244
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800245#ifdef ADHOC_SUPPORTED
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800246 // associate the menu with the tray icon
247 m_trayIcon->setContextMenu(m_trayIconMenu);
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800248#endif
Jared Lindblomb4032e22013-01-17 23:50:51 -0800249
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800250 // handle left click of icon
251 connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
Jared Lindblom06405c42013-01-17 20:48:39 -0800252}
253
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800254void
255ChronoShareGui::onAdHocChange (bool state)
256{
257#ifdef ADHOC_SUPPORTED
258 if (m_wifiAction->isChecked ())
259 {
260 QMessageBox msgBox;
261 msgBox.setText ("WARNING: your WiFi will be disconnected");
262 msgBox.setIcon (QMessageBox::Warning);
263 msgBox.setInformativeText("AdHoc WiFi will disconnect your current WiFi.\n Are you sure that you are OK with that?");
264 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
265 msgBox.setDefaultButton(QMessageBox::Cancel);
266 int ret = msgBox.exec();
267
268 if (ret == QMessageBox::Cancel)
269 {
270 m_wifiAction->setChecked (false);
271 }
272 else
273 {
274
275 m_wifiAction->setText (tr("Disable AdHoc WiFI"));
276
277 // create adhoc
278 m_executor.execute (Adhoc::CreateAdhoc);
279 }
280 }
281 else
282 {
283 m_wifiAction->setText (tr("Enable AdHoc WiFI"));
284
285 // disable adhoc
286 m_executor.execute (Adhoc::DestroyAdhoc);
287
288 // a trick in DestroyAdhoc ensures that WiFi will be reconnected to a default WiFi
289 }
290#endif
291}
292
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800293#ifdef SPARKLE_SUPPORTED
294void
295ChronoShareGui::onCheckForUpdates()
296{
297 m_autoUpdate->checkForUpdates();
298}
299#endif
300
Jared Lindblom06405c42013-01-17 20:48:39 -0800301void ChronoShareGui::setIcon()
302{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800303 // set the icon image
304 m_trayIcon->setIcon(QIcon(":/images/friends-group-icon.png"));
Jared Lindblom06405c42013-01-17 20:48:39 -0800305}
306
307void ChronoShareGui::openSharedFolder()
308{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800309 // Alex: isn't there an OS-independent way in QT for this?
Jared Lindblomb4032e22013-01-17 23:50:51 -0800310
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800311 // tell Finder to open the shared folder
312 QStringList scriptArgs;
313 scriptArgs << QLatin1String("-e")
314 << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")
315 .arg(m_dirPath);
Jared Lindblomb4032e22013-01-17 23:50:51 -0800316
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800317 // execute the commands to make it happen
318 QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
Jared Lindblomb4032e22013-01-17 23:50:51 -0800319
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800320 // clear command arguments
321 scriptArgs.clear();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800322
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800323 // tell Finder to appear
324 scriptArgs << QLatin1String("-e")
325 << QLatin1String("tell application \"Finder\" to activate");
326
327 // execute the commands to make it happen
328 QProcess::execute("/usr/bin/osascript", scriptArgs);
Jared Lindblom06405c42013-01-17 20:48:39 -0800329}
Jared Lindblomb4032e22013-01-17 23:50:51 -0800330
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800331void ChronoShareGui::changeSettings()
332{
333 if(!editUsername->text().isEmpty())
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -0800334 m_username = editUsername->text().trimmed();
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800335 else
336 editUsername->setText(m_username);
337
338 if(!editSharedFolder->text().isEmpty())
Zhenkai Zhuf3ea97a2013-01-30 15:20:52 -0800339 m_sharedFolderName = editSharedFolder->text().trimmed();
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800340 else
341 editSharedFolder->setText(m_sharedFolderName);
342
343 saveSettings();
344 this->hide();
Zhenkai Zhud5756312013-01-31 13:49:45 -0800345
346 startBackend();
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800347}
348
Jared Lindblomb4032e22013-01-17 23:50:51 -0800349void ChronoShareGui::openFileDialog()
350{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800351 // prompt user for new directory
352 QString tempPath = QFileDialog::getExistingDirectory(this, tr("Choose a new folder"),
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800353 m_dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
354 QFileInfo qFileInfo (tempPath);
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800355
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800356 if(qFileInfo.isDir())
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800357 {
358 m_dirPath = tempPath;
359 editSharedFolderPath->setText(m_dirPath);
360 }
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800361 else
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800362 {
363 openMessageBox ("Error", "Not a valid folder, Ignoring.");
364 }
Jared Lindblomb4032e22013-01-17 23:50:51 -0800365
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800366 _LOG_DEBUG ("Selected path: " << m_dirPath.toStdString ());
Jared Lindblomb4032e22013-01-17 23:50:51 -0800367
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800368 // save settings
369 saveSettings();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800370}
371
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800372void ChronoShareGui::trayIconClicked (QSystemTrayIcon::ActivationReason reason)
Jared Lindblomb4032e22013-01-17 23:50:51 -0800373{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800374 // if double clicked, open shared folder
375 if(reason == QSystemTrayIcon::DoubleClick)
Jared Lindblomb4032e22013-01-17 23:50:51 -0800376 {
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800377 openSharedFolder();
Jared Lindblomb4032e22013-01-17 23:50:51 -0800378 }
379}
380
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800381void ChronoShareGui::viewSettings()
Jared Lindblomb4032e22013-01-17 23:50:51 -0800382{
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800383 //simple for now
384 this->show();
Zhenkai Zhud5756312013-01-31 13:49:45 -0800385 this->raise();
386 this->activateWindow();
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800387}
388
389bool ChronoShareGui::loadSettings()
390{
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800391 bool successful = true;
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800392
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800393 // Load Settings
394 // QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
395 QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
Jared Lindblom5d7e51e2013-01-18 00:59:34 -0800396
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800397 // _LOG_DEBUG (lexical_cast<string> (settings.allKeys()));
398
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800399 if(settings.contains("username"))
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800400 {
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800401 m_username = settings.value("username", "admin").toString();
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800402 }
403 else
404 {
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800405 successful = false;
406 }
407
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800408 editUsername->setText(m_username);
409
410 if(settings.contains("sharedfoldername"))
411 {
412 m_sharedFolderName = settings.value("sharedfoldername", "shared").toString();
413 }
414 else
415 {
416 successful = false;
417 }
418
419 editSharedFolder->setText(m_sharedFolderName);
420
421 if(settings.contains("dirPath"))
422 {
423 m_dirPath = settings.value("dirPath", QDir::homePath()).toString();
424 }
425 else
426 {
427 successful = false;
428 }
429
430 editSharedFolderPath->setText(m_dirPath);
431
432 _LOG_DEBUG ("Found configured path: " << (successful ? m_dirPath.toStdString () : std::string("no")));
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800433
434 return successful;
Jared Lindblomb4032e22013-01-17 23:50:51 -0800435}
436
437void ChronoShareGui::saveSettings()
438{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800439 // Save Settings
440 // QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
441 QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800442
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800443 settings.setValue("dirPath", m_dirPath);
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800444 settings.setValue("username", m_username);
445 settings.setValue("sharedfoldername", m_sharedFolderName);
Jared Lindblomb4032e22013-01-17 23:50:51 -0800446}
447
448void ChronoShareGui::closeEvent(QCloseEvent* event)
449{
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800450 _LOG_DEBUG ("Close Event")
Jared Lindblomc8ffd592013-01-25 00:00:30 -0800451 this->hide();
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800452 event->ignore(); // don't let the event propagate to the base class
Jared Lindblomb4032e22013-01-17 23:50:51 -0800453}
Jared Lindblomdc845f02013-01-18 17:29:40 -0800454
455#if WAF
456#include "chronosharegui.moc"
457#include "chronosharegui.cpp.moc"
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800458#endif