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

void TRWindow::AddEntry ( BEntry *  torrent  ) 

Adds the file specified by *torrent to the Transmission engine. Then adds a new TRTransfer item in the transfers list. This item holds cached information about the torrent entry and node. These TRTransmission items are _NOT_ guaranteed to render the entry they were created from.

Definition at line 152 of file TRWindow.cpp.

References AsynchStartTorrent(), worker_info::index, StartTorrent(), and worker_info::window.

Referenced by RescanTorrents().

                                       {
      node_ref node;
      if (torrent->GetNodeRef(&node) == B_OK) {
            if (watch_node(&node, B_WATCH_NAME, this) == B_OK) {
                  BPath path;
                  torrent->GetPath(&path);
                  
                  // Try adding the torrent to the engine.
                  int addStatus = tr_torrentInit(engine, path.Path());
                  if (addStatus == 0 && Lock()) { // Success. Add the TRTorrent item.
                        transfers->AddItem(new TRTransfer(path.Path(), node));
                        
                        bool autoStart = true;
                        
                        // Decide if we should auto-start this torrent or not.
                        BString prefName("download.");
                        prefName << path.Path() << ".running";
                        
                        Prefs *prefs = new Prefs(TRANSMISSION_SETTINGS);
                        if (prefs->FindBool(prefName.String(), &autoStart) != B_OK) {
                              autoStart = true;
                        }
                        delete prefs;
                        
                        if (autoStart) {
                              // Start the newly added torrent.
                              worker_info *startData = (worker_info*)calloc(1, sizeof(worker_info));
                              startData->window = this;
                              startData->index = tr_torrentCount(engine) - 1;
                              thread_id start_thread = spawn_thread(TRWindow::AsynchStartTorrent, "BirthCanal",
                                                                    B_NORMAL_PRIORITY, (void *)startData);
                              if (!((start_thread) < B_OK)) {
                                    resume_thread(start_thread);
                              } else { // Fallback and start the old way.
                                    StartTorrent(startData->index);
                                    free(startData);
                              }
                        }
                        Unlock();
                  } else {
                        bool duplicate = false;
                        TRTransfer* tr;
                        for (int32 i = 0; i < transfers->CountItems(); i++) {
                              tr = (TRTransfer*)transfers->ItemAt(i);
                              if (tr->GetCachedNodeRef() == node) {
                                    duplicate = true;
                              }
                        }
                        if (!duplicate) {
                              BString errmsg("An error occurred trying to read ");
                              char namebuf[B_FILE_NAME_LENGTH];
                              torrent->GetName(namebuf);
                              errmsg << namebuf;
                              errmsg << ".";
                              
                              BAlert *error = new BAlert("Error Opening Torrent", 
                                     errmsg.String(), 
                                     "Ok", NULL, NULL, 
                                     B_WIDTH_AS_USUAL, B_WARNING_ALERT);
                              error->Go();
                              torrent->Remove();
                        }
                  }
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index