Browse Source

Use QPointer when interesting

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
43dcbf776b
  1. 11
      src/GUI.cpp
  2. 6
      src/GUI.h
  3. 9
      src/bittorrent.cpp
  4. 7
      src/bittorrent.h
  5. 23
      src/deleteThread.h

11
src/GUI.cpp

@ -34,14 +34,13 @@ @@ -34,14 +34,13 @@
#include <QTcpServer>
#include <QTcpSocket>
#endif
#include <stdlib.h>
#include <QCloseEvent>
#include <QShortcut>
#include <QLabel>
#include <QModelIndex>
#include "GUI.h"
#include "httpserver.h"
#include "downloadingTorrents.h"
#include "misc.h"
#include "createtorrent_imp.h"
@ -56,8 +55,9 @@ @@ -56,8 +55,9 @@
#include "options_imp.h"
#include "previewSelect.h"
#include "allocationDlg.h"
#include "stdlib.h"
#include <stdlib.h>
#include "console_imp.h"
#include "httpserver.h"
using namespace libtorrent;
@ -472,7 +472,7 @@ void GUI::acceptConnection() { @@ -472,7 +472,7 @@ void GUI::acceptConnection() {
}
void GUI::readParamsOnSocket() {
if(clientConnection != 0) {
if(clientConnection) {
QByteArray params = clientConnection->readAll();
if(!params.isEmpty()) {
processParams(QString::fromUtf8(params.data()).split(QString::fromUtf8("\n")));
@ -1488,7 +1488,6 @@ void GUI::createSystrayDelayed() { @@ -1488,7 +1488,6 @@ void GUI::createSystrayDelayed() {
createTrayIcon();
systrayIntegration = true;
delete systrayCreator;
systrayCreator = 0;
} else {
if(timeout) {
// Retry a bit later
@ -1498,7 +1497,6 @@ void GUI::createSystrayDelayed() { @@ -1498,7 +1497,6 @@ void GUI::createSystrayDelayed() {
// Timed out, apparently system really does not
// support systray icon
delete systrayCreator;
systrayCreator = 0;
}
}
}
@ -1562,7 +1560,6 @@ void GUI::OptionsSaved(bool deleteOptions) { @@ -1562,7 +1560,6 @@ void GUI::OptionsSaved(bool deleteOptions) {
else if(httpServer)
{
delete httpServer;
httpServer = 0;
}
// Update session
configureSession(deleteOptions);

6
src/GUI.h

@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
#include <QProcess>
#include <QSystemTrayIcon>
#include <QPointer>
#include "ui_MainWindow.h"
#include "qtorrenthandle.h"
@ -66,7 +66,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -66,7 +66,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
QTabWidget *tabs;
options_imp *options;
QSystemTrayIcon *myTrayIcon;
QTimer *systrayCreator;
QPointer<QTimer> systrayCreator;
QMenu *myTrayIconMenu;
DownloadingTorrents *downloadingTorrentTab;
FinishedTorrents *finishedTorrentTab;
@ -97,7 +97,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -97,7 +97,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
// RSS
RSSImp *rssWidget;
// Web UI
HttpServer *httpServer;
QPointer<HttpServer> httpServer;
// Misc
#ifdef QT_4_4
QLocalServer *localServer;

9
src/bittorrent.cpp

@ -97,9 +97,9 @@ bittorrent::~bittorrent() { @@ -97,9 +97,9 @@ bittorrent::~bittorrent() {
delete deleter;
delete fastResumeSaver;
delete timerAlerts;
if(BigRatioTimer != 0)
if(BigRatioTimer)
delete BigRatioTimer;
if(filterParser != 0)
if(filterParser)
delete filterParser;
delete downloader;
if(queueingEnabled) {
@ -1558,7 +1558,7 @@ void bittorrent::disableDirectoryScanning() { @@ -1558,7 +1558,7 @@ void bittorrent::disableDirectoryScanning() {
timerScan->stop();
}
}
if(timerScan != 0)
if(timerScan)
delete timerScan;
}
@ -1618,7 +1618,6 @@ void bittorrent::setDeleteRatio(float ratio) { @@ -1618,7 +1618,6 @@ void bittorrent::setDeleteRatio(float ratio) {
} else {
if(max_ratio != -1 && ratio == -1) {
delete BigRatioTimer;
BigRatioTimer = 0;
}
}
if(max_ratio != ratio) {
@ -1643,7 +1642,7 @@ bool bittorrent::loadTrackerFile(QString hash) { @@ -1643,7 +1642,7 @@ bool bittorrent::loadTrackerFile(QString hash) {
t.tier = parts[1].toInt();
trackers.push_back(t);
}
if(trackers.size() != 0) {
if(!trackers.empty()) {
QTorrentHandle h = getTorrentHandle(hash);
h.replace_trackers(trackers);
h.force_reannounce();

7
src/bittorrent.h

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#include <QDateTime>
#include <QApplication>
#include <QPalette>
#include <QPointer>
#include <libtorrent/session.hpp>
#include <libtorrent/ip_filter.hpp>
@ -46,10 +47,10 @@ class bittorrent : public QObject { @@ -46,10 +47,10 @@ class bittorrent : public QObject {
private:
session *s;
QString scan_dir;
QTimer *timerScan;
QPointer<QTimer> timerScan;
QTimer *timerAlerts;
QTimer *fastResumeSaver;
QTimer *BigRatioTimer;
QPointer<QTimer> BigRatioTimer;
bool DHTEnabled;
downloadThread *downloader;
QString defaultSavePath;
@ -71,7 +72,7 @@ class bittorrent : public QObject { @@ -71,7 +72,7 @@ class bittorrent : public QObject {
bool UPnPEnabled;
bool NATPMPEnabled;
bool LSDEnabled;
FilterParserThread *filterParser;
QPointer<FilterParserThread> filterParser;
QString filterPath;
int folderScanInterval; // in seconds
bool queueingEnabled;

23
src/deleteThread.h

@ -35,27 +35,30 @@ class subDeleteThread : public QThread { @@ -35,27 +35,30 @@ class subDeleteThread : public QThread {
private:
QString save_path;
arborescence *arb;
bool abort;
public:
subDeleteThread(QObject *parent, QString saveDir, arborescence *arb) : QThread(parent), save_path(saveDir), arb(arb), abort(false){}
subDeleteThread(QObject *parent, QString saveDir, arborescence *_arb) : QThread(parent), save_path(saveDir) {
arb = _arb;
}
~subDeleteThread(){
abort = true;
wait();
qDebug("subDeleteThread successfuly deleted");
//wait();
}
signals:
// For subthreads
void deletionSuccessST(subDeleteThread* st);
void deletionFailureST(subDeleteThread* st);
//void deletionFailureST(subDeleteThread* st);
protected:
void run(){
if(arb->removeFromFS(save_path))
/*if(arb->removeFromFS(save_path))
emit deletionSuccessST(this);
else
emit deletionFailureST(this);
emit deletionFailureST(this);*/
arb->removeFromFS(save_path);
emit deletionSuccessST(this);
delete arb;
}
};
@ -99,13 +102,13 @@ class deleteThread : public QThread { @@ -99,13 +102,13 @@ class deleteThread : public QThread {
if(abort)
return;
mutex.lock();
if(torrents_list.size() != 0){
if(!torrents_list.empty()){
QPair<QString, arborescence *> torrent = torrents_list.takeFirst();
mutex.unlock();
subDeleteThread *st = new subDeleteThread(0, torrent.first, torrent.second);
subDeleteThread *st = new subDeleteThread(this, torrent.first, torrent.second);
subThreads << st;
connect(st, SIGNAL(deletionSuccessST(subDeleteThread*)), this, SLOT(deleteSubThread(subDeleteThread*)));
connect(st, SIGNAL(deletionFailureST(subDeleteThread*)), this, SLOT(deleteSubThread(subDeleteThread*)));
//connect(st, SIGNAL(deletionFailureST(subDeleteThread*)), this, SLOT(deleteSubThread(subDeleteThread*)));
st->start();
}else{
condition.wait(&mutex);

Loading…
Cancel
Save