Logo Search packages:      
Sourcecode: transmission version File versions  Download package

bool TRWindow::QuitRequested (  )  [virtual]

Handles QuitRequests. Displays a BAlert asking if the user really wants to quit if torrents are running. If affimative, then we'll stop all the running torrents.

Definition at line 341 of file TRWindow.cpp.

                             {
      bool quit = false;
      
      bool running = false;
      tr_stat_t *s;
      int max = tr_torrentStat(engine, &s);
      for (int i = 0; i < max && !running; i++) {
            running = (s[i].status &
                      (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | TR_STATUS_SEED));
      }
      free(s);
      
      if (running) {
            BString quitMsg("");
            quitMsg << "There's " << max << " torrent";
            if (max > 1) {
                  quitMsg << "s";
            }
            quitMsg << " currently running.\n"
                    << "What would you like to do?";
            
            BAlert *confirmQuit = new BAlert("Confirm Quit", quitMsg.String(),
                                             "Cancel", "Quit", NULL,
                                             B_WIDTH_AS_USUAL, B_WARNING_ALERT);
            quit = (confirmQuit->Go() == 1);
      } else {
            quit = true;
      }
      
      if (quit) {
            Prefs *prefs = new Prefs(TRANSMISSION_SETTINGS);
            prefs->SetRect("window.frame", Frame());
            
            BString strItem("");
            for (int i = 0; i < tr_torrentStat(engine, &s); i++) {
                  strItem = "download.";
                  strItem << s[i].info.torrent << ".running";
                  if (s[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | TR_STATUS_SEED)) {
                        prefs->SetBool(strItem.String(), true);
                        tr_torrentStop(engine, i);
                  } else {
                        prefs->SetBool(strItem.String(), false);
                  }
            }
            free(s);
            delete prefs;
            
            be_app->PostMessage(new BMessage(B_QUIT_REQUESTED));
      }
      return quit;
}


Generated by  Doxygen 1.6.0   Back to index