From a2c5afcf7c76c7133cbf91e10e87c1826b838bc1 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 16 Oct 2006 09:02:53 +0000 Subject: [PATCH] - display errors in stderr instead of stdout --- src/GUI.cpp | 52 +++++++++++++++++++++--------------------- src/downloadThread.h | 6 ++--- src/main.cpp | 14 ++++++------ src/options_imp.cpp | 20 ++++++++-------- src/properties_imp.cpp | 4 ++-- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/GUI.cpp b/src/GUI.cpp index feb1e14cb..fe757bef3 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -179,7 +179,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ // Use a tcp server to allow only one instance of qBittorrent tcpServer = new QTcpServer(this); if (!tcpServer->listen(QHostAddress::LocalHost, 1666)) { - std::cout << "Couldn't create socket, single instance mode won't work...\n"; + std::cerr << "Couldn't create socket, single instance mode won't work...\n"; } connect(tcpServer, SIGNAL(newConnection()), this, SLOT(AnotherInstanceConnected())); // Start connection checking timer @@ -427,7 +427,7 @@ void GUI::readParamsInFile(){ params << line; } if(params.size()){ - std::cout << "Received parameters from another instance\n"; + qDebug("Received parameters from another instance"); addTorrents(params); } paramsFile.close(); @@ -470,7 +470,7 @@ void GUI::updateDlList(){ if(!h.is_paused()){ int row = getRowFromName(fileName); if(row == -1){ - std::cout << "Error: Could not find filename in download list..\n"; + std::cerr << "Error: Could not find filename in download list..\n"; continue; } // Parse download state @@ -721,7 +721,7 @@ void GUI::saveWindowSize() const{ lastWindowSize.close(); qDebug("Saved window size"); }else{ - std::cout << "Error: Could not save last windows size\n"; + std::cerr << "Error: Could not save last windows size\n"; } } @@ -738,7 +738,7 @@ bool GUI::loadFilteredFiles(torrent_handle &h){ pieces_file.close(); QList pieces_selection_list = pieces_selection.split('\n'); if(pieces_selection_list.size() != torrentInfo.num_files()+1){ - std::cout << "Error: Corrupted pieces file\n"; + std::cerr << "Error: Corrupted pieces file\n"; return has_filtered_files; } std::vector selectionBitmask; @@ -831,7 +831,7 @@ void GUI::saveCheckedSearchEngines(int) const{ lastSearchEngines.close(); qDebug("Saved checked search engines"); }else{ - std::cout << "Error: Could not save last checked search engines\n"; + std::cerr << "Error: Could not save last checked search engines\n"; } } @@ -851,7 +851,7 @@ void GUI::saveColWidthDLList() const{ lastDLListWidth.close(); qDebug("Columns width saved"); }else{ - std::cout << "Error: Could not save last columns width in download list\n"; + std::cerr << "Error: Could not save last columns width in download list\n"; } } @@ -875,7 +875,7 @@ bool GUI::loadColWidthDLList(){ qDebug("Loaded columns width in download list"); return true; }else{ - std::cout << "Error: Could not load last columns width for download list\n"; + std::cerr << "Error: Could not load last columns width for download list\n"; return false; } } @@ -898,7 +898,7 @@ void GUI::saveColWidthSearchList() const{ lastSearchListWidth.close(); qDebug("Columns width saved in search list"); }else{ - std::cout << "Error: Could not save last columns width in search results list\n"; + std::cerr << "Error: Could not save last columns width in search results list\n"; } } @@ -922,7 +922,7 @@ bool GUI::loadColWidthSearchList(){ qDebug("Columns width loaded in search list"); return true; }else{ - std::cout << "Error: Could not load last columns width for search results list\n"; + std::cerr << "Error: Could not load last columns width for search results list\n"; return false; } } @@ -974,7 +974,7 @@ void GUI::loadCheckedSearchEngines(){ } qDebug("Checked search engines loaded"); }else{ - std::cout << "Error: Could not load last checked search engines\n"; + std::cerr << "Error: Could not load last checked search engines\n"; } } } @@ -1005,7 +1005,7 @@ void GUI::closeEvent(QCloseEvent *e){ out.unsetf(std::ios_base::skipws); bencode(std::ostream_iterator(out), dht_state); }catch (std::exception& e){ - std::cout << e.what() << "\n"; + std::cerr << e.what() << "\n"; } } // Save window size, columns size @@ -1242,7 +1242,7 @@ void GUI::deleteSelection(){ --nbTorrents; tabs->setTabText(0, tr("Transfers") +" ("+QString(misc::toString(nbTorrents).c_str())+")"); }else{ - std::cout << "Error: Could not find the torrent handle supposed to be removed\n"; + std::cerr << "Error: Could not find the torrent handle supposed to be removed\n"; } } } @@ -1417,7 +1417,7 @@ void GUI::addTorrents(const QStringList& pathsList, bool fromScanDir, const QStr ++nbTorrents; tabs->setTabText(0, tr("Transfers") +" ("+QString(misc::toString(nbTorrents).c_str())+")"); }catch (invalid_encoding& e){ // Raised by bdecode() - std::cout << "Could not decode file, reason: " << e.what() << '\n'; + std::cerr << "Could not decode file, reason: " << e.what() << '\n'; // Display warning to tell user we can't decode the torrent file if(!from_url.isNull()){ setInfoBar(tr("Unable to decode torrent file:")+" '"+from_url+"'", "red"); @@ -1488,7 +1488,7 @@ void GUI::reloadTorrent(const torrent_handle &h, bool compact_mode){ ++timeout; } if(h.is_valid()){ - std::cout << "Error: Couldn't reload the torrent\n"; + std::cerr << "Error: Couldn't reload the torrent\n"; return; } new_h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resumeData, compact_mode); @@ -1666,7 +1666,7 @@ void GUI::configureSession(){ } } }catch(std::exception& e){ - std::cout << e.what() << "\n"; + std::cerr << e.what() << "\n"; } qDebug("Session configured"); } @@ -1688,7 +1688,7 @@ void GUI::pauseAll(){ // update DL Status int row = getRowFromName(fileName); if(row == -1){ - std::cout << "Error: Filename could not be found in download list...\n"; + std::cerr << "Error: Filename could not be found in download list...\n"; continue; } DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.)); @@ -1750,7 +1750,7 @@ void GUI::startAll(){ // update DL Status int row = getRowFromName(fileName); if(row == -1){ - std::cout << "Error: Filename could not be found in download list...\n"; + std::cerr << "Error: Filename could not be found in download list...\n"; continue; } DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Connecting..."))); @@ -2062,7 +2062,7 @@ void GUI::updateNova() const{ QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup; QFile(misc::qBittorrentPath()+"nova.py").setPermissions(perm); if(provided_nova_version > getNovaVersion(misc::qBittorrentPath()+"nova.py")){ - std::cout << "updating local search plugin with shipped one\n"; + qDebug("updating local search plugin with shipped one"); // nova.py needs update QFile::remove(misc::qBittorrentPath()+"nova.py"); qDebug("Old nova removed"); @@ -2070,7 +2070,7 @@ void GUI::updateNova() const{ qDebug("New nova copied"); QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup; QFile(misc::qBittorrentPath()+"nova.py").setPermissions(perm); - std::cout << "local search plugin updated\n"; + qDebug("local search plugin updated"); } } @@ -2080,7 +2080,7 @@ void GUI::updateNova() const{ void GUI::on_update_nova_button_clicked(){ CURL *curl; std::string filePath; - std::cout << "Checking for search plugin updates on qbittorrent.org\n"; + qDebug("Checking for search plugin updates on qbittorrent.org"); // XXX: Trick to get a unique filename QTemporaryFile *tmpfile = new QTemporaryFile; if (tmpfile->open()) { @@ -2089,12 +2089,12 @@ void GUI::on_update_nova_button_clicked(){ delete tmpfile; FILE *file = fopen(filePath.c_str(), "w"); if(!file){ - std::cout << "Error: could not open temporary file...\n"; + std::cerr << "Error: could not open temporary file...\n"; } // Initilization required by libcurl curl = curl_easy_init(); if(!curl){ - std::cout << "Error: Failed to init curl...\n"; + std::cerr << "Error: Failed to init curl...\n"; fclose(file); return; } @@ -2113,14 +2113,14 @@ void GUI::on_update_nova_button_clicked(){ curl_easy_cleanup(curl); // Close tmp file fclose(file); - std::cout << "Version on qbittorrent.org: " << getNovaVersion(QString(filePath.c_str())) << '\n'; + qDebug("Version on qbittorrent.org: %f", getNovaVersion(QString(filePath.c_str()))); float version_on_server = getNovaVersion(QString(filePath.c_str())); if(version_on_server == 0.0){ //First server is down, try mirror QFile::remove(filePath.c_str()); FILE *file = fopen(filePath.c_str(), "w"); if(!file){ - std::cout << "Error: could not open temporary file...\n"; + std::cerr << "Error: could not open temporary file...\n"; } curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, "http://hydr0g3n.free.fr/nova/nova.py"); @@ -2147,7 +2147,7 @@ void GUI::on_update_nova_button_clicked(){ QString(), 0, 1)){ return; }else{ - std::cout << "Updating search plugin from qbittorrent.org\n"; + qDebug("Updating search plugin from qbittorrent.org"); QFile::remove(misc::qBittorrentPath()+"nova.py"); QFile::copy(QString(filePath.c_str()), misc::qBittorrentPath()+"nova.py"); QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup; diff --git a/src/downloadThread.h b/src/downloadThread.h index f1c371ba2..fa2c8295e 100644 --- a/src/downloadThread.h +++ b/src/downloadThread.h @@ -78,13 +78,13 @@ class downloadThread : public QThread { delete tmpfile; FILE *file = fopen(filePath.c_str(), "w"); if(!file){ - std::cout << "Error: could not open temporary file...\n"; + std::cerr << "Error: could not open temporary file...\n"; return; } // Initilization required by libcurl curl = curl_easy_init(); if(!curl){ - std::cout << "Error: Failed to init curl...\n"; + std::cerr << "Error: Failed to init curl...\n"; fclose(file); return; } @@ -114,7 +114,7 @@ class downloadThread : public QThread { errorBuffer[0]=0; /* prevent junk from being output */ return_code = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer); if(return_code){ - std::cout << "Error: failed to set error buffer in curl\n"; + std::cerr << "Error: failed to set error buffer in curl\n"; fclose(file); QFile::remove(filePath.c_str()); return; diff --git a/src/main.cpp b/src/main.cpp index 843a07815..1bbb849f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ int main(int argc, char *argv[]){ } // Set environment variable if(putenv("QBITTORRENT="VERSION)){ - std::cout << "Couldn't set environment variable...\n"; + std::cerr << "Couldn't set environment variable...\n"; } // Buggy with Qt 4.1.2 : should try with another version //Check if there is another instance running @@ -92,7 +92,7 @@ int main(int argc, char *argv[]){ QTcpSocket tcpSocket; tcpSocket.connectToHost(QHostAddress::LocalHost, 1666); if (tcpSocket.waitForConnected(1000)){ - std::cout << "Another qBittorrent instance is already running...\n"; + qDebug("Another qBittorrent instance is already running..."); // Write params to a temporary file QFile paramsFile(QDir::tempPath()+QDir::separator()+"qBT-params.txt"); int count = 0; @@ -105,17 +105,17 @@ int main(int argc, char *argv[]){ paramsFile.remove(); // Write params to the file if (!paramsFile.open(QIODevice::WriteOnly | QIODevice::Text)){ - std:: cout << "could not pass parameters\n"; + std:: cerr << "could not pass parameters\n"; return 1; } - std:: cout << "Passing parameters\n"; + qDebug("Passing parameters"); for(int i=1;i partsList = line.split(','); unsigned int nbElem = partsList.size(); if(nbElem < 2){ - std::cout << "Ipfilter.dat: line " << nbLine << " is malformed.\n"; + std::cerr << "Ipfilter.dat: line " << nbLine << " is malformed.\n"; continue; } int nbAccess = partsList.at(1).trimmed().toInt(); @@ -815,13 +815,13 @@ void options_imp::processFilterFile(const QString& filePath){ // Split IP IP = strStartIP.split('.'); if(IP.size() != 4){ - std::cout << "Ipfilter.dat: line " << nbLine << ", first IP is malformed.\n"; + std::cerr << "Ipfilter.dat: line " << nbLine << ", first IP is malformed.\n"; continue; } address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt()); IP = strEndIP.split('.'); if(IP.size() != 4){ - std::cout << "Ipfilter.dat: line " << nbLine << ", second IP is malformed.\n"; + std::cerr << "Ipfilter.dat: line " << nbLine << ", second IP is malformed.\n"; continue; } address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt()); @@ -896,7 +896,7 @@ void options_imp::on_addFilterRange_clicked(){ } QFile ipfilter(misc::qBittorrentPath() + "ipfilter.dat"); if (!ipfilter.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text)){ - std::cout << "Error: Couldn't write in ipfilter.dat"; + std::cerr << "Error: Couldn't write in ipfilter.dat"; return; } QTextStream out(&ipfilter); @@ -925,7 +925,7 @@ void options_imp::on_delFilterRange_clicked(){ // Update ipfilter.dat QFile ipfilter(misc::qBittorrentPath() + "ipfilter.dat"); if (!ipfilter.open(QIODevice::WriteOnly | QIODevice::Text)){ - std::cout << "Error: Couldn't write in ipfilter.dat"; + std::cerr << "Error: Couldn't write in ipfilter.dat"; return; } QTextStream out(&ipfilter); diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index b39e5cba6..d46336b62 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -163,7 +163,7 @@ void properties::loadFilteredFiles(){ pieces_file.close(); QList pieces_selection_list = pieces_selection.split('\n'); if(pieces_selection_list.size() != torrentInfo.num_files()+1){ - std::cout << "Error: Corrupted pieces file\n"; + std::cerr << "Error: Corrupted pieces file\n"; setAllPiecesState(true); selectionBitmask.assign(torrentInfo.num_files(), 0); return; @@ -309,7 +309,7 @@ void properties::saveFilteredFiles(){ pieces_file.remove(); // Write new files if(!pieces_file.open(QIODevice::WriteOnly | QIODevice::Text)){ - std::cout << "Error: Could not save filtered pieces\n"; + std::cerr << "Error: Could not save filtered pieces\n"; return; } for(int i=0; i