Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 1 | /* -*- 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 | #include "chronosharegui.h" |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 22 | #include "logging.h" |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 23 | #include "ccnx-wrapper.h" |
Zhenkai Zhu | f3ea97a | 2013-01-30 15:20:52 -0800 | [diff] [blame] | 24 | #include <QValidator> |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 25 | |
| 26 | #include <boost/make_shared.hpp> |
| 27 | |
| 28 | using namespace boost; |
| 29 | using namespace Ccnx; |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 31 | INIT_LOGGER ("Gui"); |
| 32 | |
| 33 | ChronoShareGui::ChronoShareGui(QWidget *parent) |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 34 | : QDialog(parent) |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 35 | , m_watcher(0) |
| 36 | , m_dispatcher(0) |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 37 | { |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 38 | |
Jared Lindblom | f4b900e | 2013-02-07 18:08:47 -0800 | [diff] [blame^] | 39 | setWindowTitle("Settings"); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 40 | |
| 41 | labelUsername = new QLabel("Username"); |
| 42 | labelSharedFolder = new QLabel("Shared Folder Name"); |
| 43 | labelSharedFolderPath = new QLabel("Shared Folder Path"); |
Zhenkai Zhu | f3ea97a | 2013-01-30 15:20:52 -0800 | [diff] [blame] | 44 | |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 45 | QRegExp regex("(/[^/]+)+$"); |
Zhenkai Zhu | f3ea97a | 2013-01-30 15:20:52 -0800 | [diff] [blame] | 46 | QValidator *prefixValidator = new QRegExpValidator(regex, this); |
| 47 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 48 | editUsername = new QLineEdit(); |
Zhenkai Zhu | f3ea97a | 2013-01-30 15:20:52 -0800 | [diff] [blame] | 49 | editUsername->setValidator(prefixValidator); |
| 50 | |
| 51 | QRegExp noPureWhiteSpace("^\\S+.*$"); |
| 52 | QValidator *wsValidator = new QRegExpValidator(noPureWhiteSpace, this); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 53 | editSharedFolder = new QLineEdit(); |
Zhenkai Zhu | f3ea97a | 2013-01-30 15:20:52 -0800 | [diff] [blame] | 54 | editSharedFolder->setValidator(wsValidator); |
| 55 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 56 | editSharedFolderPath = new QLineEdit(); |
| 57 | editSharedFolderPath->setReadOnly(true); |
| 58 | QPalette pal = editSharedFolderPath->palette(); |
| 59 | pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Disabled, QPalette::Base)); |
| 60 | editSharedFolderPath->setPalette(pal); |
| 61 | button = new QPushButton("Submit"); |
| 62 | label = new QLabel(); |
| 63 | |
| 64 | connect(button, SIGNAL(clicked()), this, SLOT(changeSettings())); |
| 65 | |
| 66 | mainLayout = new QVBoxLayout; //vertically |
| 67 | mainLayout->addWidget(labelUsername); |
| 68 | mainLayout->addWidget(editUsername); |
| 69 | mainLayout->addWidget(labelSharedFolder); |
| 70 | mainLayout->addWidget(editSharedFolder); |
| 71 | mainLayout->addWidget(labelSharedFolderPath); |
| 72 | mainLayout->addWidget(editSharedFolderPath); |
| 73 | mainLayout->addWidget(button); |
| 74 | mainLayout->addWidget(label); |
| 75 | setLayout(mainLayout); |
| 76 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 77 | // create actions that result from clicking a menu option |
| 78 | createActions(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 79 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 80 | // create tray icon |
| 81 | createTrayIcon(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 83 | // set icon image |
| 84 | setIcon(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 86 | // show tray icon |
| 87 | m_trayIcon->show(); |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 88 | |
| 89 | // Dispatcher(const boost::filesystem::path &path, const std::string &localUserName, const Ccnx::Name &localPrefix, |
| 90 | // const std::string &sharedFolder, const boost::filesystem::path &rootDir, |
| 91 | // Ccnx::CcnxWrapperPtr ccnx, SchedulerPtr scheduler, int poolSize = 2); |
| 92 | |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 93 | // load settings |
| 94 | if(!loadSettings()) |
| 95 | { |
| 96 | // prompt user to choose folder |
| 97 | openMessageBox("First Time Setup", "Please enter a username, shared folder name and choose the shared folder path on your local filesystem."); |
| 98 | viewSettings(); |
| 99 | openFileDialog(); |
| 100 | viewSettings(); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | startBackend(); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | ChronoShareGui::startBackend() |
| 110 | { |
| 111 | if (m_watcher != 0 && m_dispatcher != 0) |
| 112 | { |
| 113 | return; |
| 114 | } |
| 115 | |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 116 | m_dispatcher = new Dispatcher (m_username.toStdString (), m_sharedFolderName.toStdString (), |
| 117 | m_dirPath.toStdString (), make_shared<CcnxWrapper> ()); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 118 | |
| 119 | // Alex: this **must** be here, otherwise m_dirPath will be uninitialized |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 120 | m_watcher = new FsWatcher (m_dirPath, |
| 121 | bind (&Dispatcher::Did_LocalFile_AddOrModify, m_dispatcher, _1), |
Zhenkai Zhu | d175627 | 2013-02-01 17:02:18 -0800 | [diff] [blame] | 122 | bind (&Dispatcher::Did_LocalFile_Delete, m_dispatcher, _1)); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | ChronoShareGui::~ChronoShareGui() |
| 126 | { |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 127 | delete m_watcher; // stop filewatching ASAP |
Alexander Afanasyev | 9ca444e | 2013-01-25 16:29:35 -0800 | [diff] [blame] | 128 | delete m_dispatcher; // stop dispatcher ASAP, but after watcher (to prevent triggering callbacks on deleted object) |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 130 | // cleanup |
| 131 | delete m_trayIcon; |
| 132 | delete m_trayIconMenu; |
| 133 | delete m_openFolder; |
| 134 | delete m_viewSettings; |
| 135 | delete m_changeFolder; |
| 136 | delete m_quitProgram; |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 137 | |
| 138 | delete labelUsername; |
| 139 | delete labelSharedFolder; |
| 140 | delete editUsername; |
| 141 | delete editSharedFolder; |
| 142 | delete button; |
| 143 | delete label; |
| 144 | delete mainLayout; |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | void ChronoShareGui::openMessageBox(QString title, QString text) |
| 148 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 149 | QMessageBox messageBox(this); |
| 150 | messageBox.setWindowTitle(title); |
| 151 | messageBox.setText(text); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 152 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 153 | messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png")); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 154 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 155 | messageBox.exec(); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void ChronoShareGui::openMessageBox(QString title, QString text, QString infotext) |
| 159 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 160 | QMessageBox messageBox(this); |
| 161 | messageBox.setWindowTitle(title); |
| 162 | messageBox.setText(text); |
| 163 | messageBox.setInformativeText(infotext); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 164 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 165 | messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png")); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 166 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 167 | messageBox.exec(); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void ChronoShareGui::createActions() |
| 171 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 172 | // create the "open folder" action |
| 173 | m_openFolder = new QAction(tr("&Open Folder"), this); |
| 174 | connect(m_openFolder, SIGNAL(triggered()), this, SLOT(openSharedFolder())); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 175 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 176 | // create the "view settings" action |
| 177 | m_viewSettings = new QAction(tr("&View Settings"), this); |
| 178 | connect(m_viewSettings, SIGNAL(triggered()), this, SLOT(viewSettings())); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 179 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 180 | // create the "change folder" action |
| 181 | m_changeFolder = new QAction(tr("&Change Folder"), this); |
| 182 | connect(m_changeFolder, SIGNAL(triggered()), this, SLOT(openFileDialog())); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 183 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 184 | // create the "quit program" action |
| 185 | m_quitProgram = new QAction(tr("&Quit"), this); |
| 186 | connect(m_quitProgram, SIGNAL(triggered()), qApp, SLOT(quit())); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void ChronoShareGui::createTrayIcon() |
| 190 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 191 | // create a new icon menu |
| 192 | m_trayIconMenu = new QMenu(this); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 193 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 194 | // add actions to the menu |
| 195 | m_trayIconMenu->addAction(m_openFolder); |
| 196 | m_trayIconMenu->addSeparator(); |
| 197 | m_trayIconMenu->addAction(m_viewSettings); |
| 198 | m_trayIconMenu->addAction(m_changeFolder); |
| 199 | m_trayIconMenu->addSeparator(); |
| 200 | m_trayIconMenu->addAction(m_quitProgram); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 201 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 202 | // create new tray icon |
| 203 | m_trayIcon = new QSystemTrayIcon(this); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 204 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 205 | // associate the menu with the tray icon |
| 206 | m_trayIcon->setContextMenu(m_trayIconMenu); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 207 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 208 | // handle left click of icon |
| 209 | connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason))); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void ChronoShareGui::setIcon() |
| 213 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 214 | // set the icon image |
| 215 | m_trayIcon->setIcon(QIcon(":/images/friends-group-icon.png")); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void ChronoShareGui::openSharedFolder() |
| 219 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 220 | // Alex: isn't there an OS-independent way in QT for this? |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 221 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 222 | // tell Finder to open the shared folder |
| 223 | QStringList scriptArgs; |
| 224 | scriptArgs << QLatin1String("-e") |
| 225 | << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"") |
| 226 | .arg(m_dirPath); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 227 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 228 | // execute the commands to make it happen |
| 229 | QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 230 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 231 | // clear command arguments |
| 232 | scriptArgs.clear(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 233 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 234 | // tell Finder to appear |
| 235 | scriptArgs << QLatin1String("-e") |
| 236 | << QLatin1String("tell application \"Finder\" to activate"); |
| 237 | |
| 238 | // execute the commands to make it happen |
| 239 | QProcess::execute("/usr/bin/osascript", scriptArgs); |
Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame] | 240 | } |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 241 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 242 | void ChronoShareGui::changeSettings() |
| 243 | { |
| 244 | if(!editUsername->text().isEmpty()) |
Zhenkai Zhu | f3ea97a | 2013-01-30 15:20:52 -0800 | [diff] [blame] | 245 | m_username = editUsername->text().trimmed(); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 246 | else |
| 247 | editUsername->setText(m_username); |
| 248 | |
| 249 | if(!editSharedFolder->text().isEmpty()) |
Zhenkai Zhu | f3ea97a | 2013-01-30 15:20:52 -0800 | [diff] [blame] | 250 | m_sharedFolderName = editSharedFolder->text().trimmed(); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 251 | else |
| 252 | editSharedFolder->setText(m_sharedFolderName); |
| 253 | |
| 254 | saveSettings(); |
| 255 | this->hide(); |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 256 | |
| 257 | startBackend(); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 260 | void ChronoShareGui::openFileDialog() |
| 261 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 262 | // prompt user for new directory |
| 263 | QString tempPath = QFileDialog::getExistingDirectory(this, tr("Choose a new folder"), |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 264 | m_dirPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); |
| 265 | QFileInfo qFileInfo (tempPath); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 266 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 267 | if(qFileInfo.isDir()) |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 268 | { |
| 269 | m_dirPath = tempPath; |
| 270 | editSharedFolderPath->setText(m_dirPath); |
| 271 | } |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 272 | else |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 273 | { |
| 274 | openMessageBox ("Error", "Not a valid folder, Ignoring."); |
| 275 | } |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 276 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 277 | _LOG_DEBUG ("Selected path: " << m_dirPath.toStdString ()); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 278 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 279 | // save settings |
| 280 | saveSettings(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 283 | void ChronoShareGui::trayIconClicked (QSystemTrayIcon::ActivationReason reason) |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 284 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 285 | // if double clicked, open shared folder |
| 286 | if(reason == QSystemTrayIcon::DoubleClick) |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 287 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 288 | openSharedFolder(); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 292 | void ChronoShareGui::viewSettings() |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 293 | { |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 294 | //simple for now |
| 295 | this->show(); |
Zhenkai Zhu | d575631 | 2013-01-31 13:49:45 -0800 | [diff] [blame] | 296 | this->raise(); |
| 297 | this->activateWindow(); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | bool ChronoShareGui::loadSettings() |
| 301 | { |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 302 | bool successful = true; |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 303 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 304 | // Load Settings |
| 305 | // QSettings settings(m_settingsFilePath, QSettings::NativeFormat); |
| 306 | QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare"); |
Jared Lindblom | 5d7e51e | 2013-01-18 00:59:34 -0800 | [diff] [blame] | 307 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 308 | // _LOG_DEBUG (lexical_cast<string> (settings.allKeys())); |
| 309 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 310 | if(settings.contains("username")) |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 311 | { |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 312 | m_username = settings.value("username", "admin").toString(); |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 313 | } |
| 314 | else |
| 315 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 316 | successful = false; |
| 317 | } |
| 318 | |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 319 | editUsername->setText(m_username); |
| 320 | |
| 321 | if(settings.contains("sharedfoldername")) |
| 322 | { |
| 323 | m_sharedFolderName = settings.value("sharedfoldername", "shared").toString(); |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | successful = false; |
| 328 | } |
| 329 | |
| 330 | editSharedFolder->setText(m_sharedFolderName); |
| 331 | |
| 332 | if(settings.contains("dirPath")) |
| 333 | { |
| 334 | m_dirPath = settings.value("dirPath", QDir::homePath()).toString(); |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | successful = false; |
| 339 | } |
| 340 | |
| 341 | editSharedFolderPath->setText(m_dirPath); |
| 342 | |
| 343 | _LOG_DEBUG ("Found configured path: " << (successful ? m_dirPath.toStdString () : std::string("no"))); |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 344 | |
| 345 | return successful; |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void ChronoShareGui::saveSettings() |
| 349 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 350 | // Save Settings |
| 351 | // QSettings settings(m_settingsFilePath, QSettings::NativeFormat); |
| 352 | QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare"); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 353 | |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 354 | settings.setValue("dirPath", m_dirPath); |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 355 | settings.setValue("username", m_username); |
| 356 | settings.setValue("sharedfoldername", m_sharedFolderName); |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void ChronoShareGui::closeEvent(QCloseEvent* event) |
| 360 | { |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 361 | _LOG_DEBUG ("Close Event") |
Jared Lindblom | c8ffd59 | 2013-01-25 00:00:30 -0800 | [diff] [blame] | 362 | this->hide(); |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 363 | event->ignore(); // don't let the event propagate to the base class |
Jared Lindblom | b4032e2 | 2013-01-17 23:50:51 -0800 | [diff] [blame] | 364 | } |
Jared Lindblom | dc845f0 | 2013-01-18 17:29:40 -0800 | [diff] [blame] | 365 | |
| 366 | #if WAF |
| 367 | #include "chronosharegui.moc" |
| 368 | #include "chronosharegui.cpp.moc" |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 369 | #endif |