| 120 | | /* Set correct tray icon */ |
| 121 | | _trayIcon->setIcon(QPixmap(":/images/tor_on32.png")); |
| 122 | | |
| 123 | | /* Set ToolTip */ |
| 124 | | _trayIcon->setToolTip(QString("Tor is started")); |
| | 138 | QString errmsg; |
| | 139 | if (!_torControl->start(&errmsg)) { |
| | 140 | QMessageBox::warning(this, tr("Error Starting Tor"), |
| | 141 | tr("Vidalia was unable to start Tor.\r\n\r\nError: ") + errmsg, |
| | 142 | QMessageBox::Ok, QMessageBox::NoButton); |
| | 143 | } |
| | 144 | } |
| | 145 | |
| | 146 | /** Slot: Called when the Tor process is started. It will connect the control |
| | 147 | * socket and set the icons and tooltips accordingly. */ |
| | 148 | void MainWindow::started() |
| | 149 | { |
| | 150 | /* Set the window icon */ |
| | 151 | QApplication::setWindowIcon(QIcon(IMG_TOR_RUNNING)); |
| | 152 | |
| | 153 | /* Set correct tray icon and tooltip */ |
| | 154 | _trayIcon->setIcon(QPixmap(IMG_TOR_RUNNING)); |
| | 155 | _trayIcon->setToolTip(tr("Tor is started")); |
| 130 | | /* FIXME Add code for starting Tor */ |
| 131 | | |
| 132 | | } |
| 133 | | |
| 134 | | /* |
| 135 | | Stops Tor, modifies tray icon and tray menu appropriately |
| | 161 | /* Try to connect to Tor's control port */ |
| | 162 | QString errmsg; |
| | 163 | if (!_torControl->connect(&errmsg)) { |
| | 164 | /* There's a possibility that Tor has started, but it just hasn't had a |
| | 165 | * chance to bind the control socket yet. So pause for a second and try |
| | 166 | * again.*/ |
| | 167 | v_sleep(1); |
| | 168 | if(!_torControl->connect(&errmsg)) { |
| | 169 | /* Ok, ok. It really isn't going to connect. I give up. */ |
| | 170 | QMessageBox::warning(this, tr("Error Connecting to Tor"), |
| | 171 | tr("Tor started successfully, but Vidalia was unable to " |
| | 172 | "connect to it. Check your control port settings and try " |
| | 173 | "again.\r\n\r\n") + errmsg, |
| | 174 | QMessageBox::Ok, QMessageBox::NoButton); |
| | 175 | } |
| | 176 | } else { |
| | 177 | /* The controller connected, so now send the AUTHENTICATE command */ |
| | 178 | if (!_torControl->authenticate(&errmsg)) { |
| | 179 | QMessageBox::warning(this, tr("Authentication Error"), |
| | 180 | tr("Vidalia was unable to authenticate itself to Tor." |
| | 181 | "Check your authentication information and try again." |
| | 182 | "\r\n\r\nError: ") + errmsg, |
| | 183 | QMessageBox::Ok, QMessageBox::NoButton); |
| | 184 | } |
| | 185 | } |
| | 186 | } |
| | 187 | |
| | 188 | /* |
| | 189 | Stops Tor |
| 139 | | /* Set correct tray icon */ |
| 140 | | _trayIcon->setIcon(QPixmap(":/images/tor_off32.png")); |
| 141 | | |
| 142 | | /* Set ToolTip */ |
| 143 | | _trayIcon->setToolTip(QString("Tor is stopped")); |
| | 193 | QString errmsg; |
| | 194 | |
| | 195 | /* Disconnect the controller. Note that we don't check any error messages or |
| | 196 | * return values, since we'll just be killing Tor anyway. */ |
| | 197 | if (_torControl->isConnected()) { |
| | 198 | _torControl->disconnect(); |
| | 199 | } |
| | 200 | |
| | 201 | /* Stop the Tor process */ |
| | 202 | _isIntentionalExit = true; |
| | 203 | if (!_torControl->stop(&errmsg)) { |
| | 204 | QMessageBox::warning(this, tr("Error Stopping Tor"), |
| | 205 | tr("Vidalia was unable to stop Tor.\r\n\r\nError: ") + errmsg, |
| | 206 | QMessageBox::Ok, QMessageBox::NoButton); |
| | 207 | } |
| | 208 | _isIntentionalExit = false; |
| | 209 | } |
| | 210 | |
| | 211 | /** Slot: Called when the Tor process has exited. It will adjust the tray |
| | 212 | * icons and tooltips accordingly. */ |
| | 213 | void MainWindow::stopped(int exitCode, QProcess::ExitStatus exitStatus) |
| | 214 | { |
| | 215 | /* Set the window icon */ |
| | 216 | QApplication::setWindowIcon(QIcon(IMG_TOR_STOPPED)); |
| | 217 | |
| | 218 | /* Set correct tray icon and tooltip */ |
| | 219 | _trayIcon->setIcon(QPixmap(IMG_TOR_STOPPED)); |
| | 220 | _trayIcon->setToolTip(tr("Tor is stopped")); |
| 149 | | /* FIXME Add code for stopping Tor */ |
| 150 | | |
| | 226 | /* Check if the Tor process fell over or exited cleanly */ |
| | 227 | if (exitStatus == QProcess::CrashExit) { |
| | 228 | if (!_isIntentionalExit) { |
| | 229 | QMessageBox::warning(this, tr("Tor Crashed"), |
| | 230 | tr("Vidalia detected that the Tor process crashed. " |
| | 231 | "Please check the message log."), |
| | 232 | QMessageBox::Ok, QMessageBox::NoButton); |
| | 233 | } |
| | 234 | } else if (exitCode != 0) { |
| | 235 | /* A quick overview of Tor's code tells me that if it catches a SIGTERM or |
| | 236 | * SIGINT, Tor will exit(0). We might need to change this warning message |
| | 237 | * if this turns out to not be the case. */ |
| | 238 | QMessageBox::warning(this, tr("Tor Exited"), |
| | 239 | tr("Tor exited and returned a non-zero exit code. " |
| | 240 | "Please check the message log."), |
| | 241 | QMessageBox::Ok, QMessageBox::NoButton); |
| | 242 | } |