mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 04:24:23 +00:00
Fix execution log lines selection and copying
This commit is contained in:
parent
94a23cf1d4
commit
6606cf60af
@ -5,6 +5,7 @@
|
||||
- FEATURE: Add support for anonymous mode (libtorrent >= v0.16)
|
||||
- FEATURE: Add quick "set as default save path" checkbox to torrent addition dialog (sledgehammer999)
|
||||
- BUGFIX: Add tray menu entry for toggling window visibility
|
||||
- BUGFIX: Fix execution log lines selection and copying
|
||||
- COSMETIC: Display speed at the beginning of the Window title
|
||||
- OTHER: Display libraries versions in about dialog (sledgehammer999)
|
||||
|
||||
|
@ -34,14 +34,21 @@
|
||||
#include "ui_executionlog.h"
|
||||
#include "qbtsession.h"
|
||||
#include "iconprovider.h"
|
||||
#include "loglistwidget.h"
|
||||
|
||||
ExecutionLog::ExecutionLog(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ExecutionLog)
|
||||
QWidget(parent),
|
||||
ui(new Ui::ExecutionLog),
|
||||
m_logList(new LogListWidget(MAX_LOG_MESSAGES)),
|
||||
m_banList(new LogListWidget(MAX_LOG_MESSAGES))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->tabConsole->setTabIcon(0, IconProvider::instance()->getIcon("view-calendar-journal"));
|
||||
ui->tabConsole->setTabIcon(1, IconProvider::instance()->getIcon("view-filter"));
|
||||
ui->tabGeneral->layout()->addWidget(m_logList);
|
||||
ui->tabBan->layout()->addWidget(m_banList);
|
||||
|
||||
const QStringList log_msgs = QBtSession::instance()->getConsoleMessages();
|
||||
foreach(const QString& msg, log_msgs)
|
||||
addLogMessage(msg);
|
||||
@ -54,29 +61,17 @@ ExecutionLog::ExecutionLog(QWidget *parent) :
|
||||
|
||||
ExecutionLog::~ExecutionLog()
|
||||
{
|
||||
delete m_logList;
|
||||
delete m_banList;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ExecutionLog::addLogMessage(const QString &msg)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
QLabel *lbl = new QLabel(msg);
|
||||
lbl->setContentsMargins(4, 2, 4, 2);
|
||||
item->setSizeHint(lbl->sizeHint());
|
||||
ui->logList->insertItem(0, item);
|
||||
ui->logList->setItemWidget(item, lbl);
|
||||
if(ui->logList->count() > MAX_LOG_MESSAGES)
|
||||
delete ui->logList->takeItem(ui->logList->count()-1);
|
||||
m_logList->appendLine(msg);
|
||||
}
|
||||
|
||||
void ExecutionLog::addBanMessage(const QString &msg)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem;
|
||||
QLabel *lbl = new QLabel(msg);
|
||||
lbl->setContentsMargins(4, 2, 4, 2);
|
||||
item->setSizeHint(lbl->sizeHint());
|
||||
ui->banList->insertItem(0, item);
|
||||
ui->banList->setItemWidget(item, lbl);
|
||||
if(ui->banList->count() > MAX_LOG_MESSAGES)
|
||||
delete ui->banList->takeItem(ui->banList->count()-1);
|
||||
m_banList->appendLine(msg);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class ExecutionLog;
|
||||
}
|
||||
class LogListWidget;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class ExecutionLog : public QWidget
|
||||
@ -52,7 +53,11 @@ public slots:
|
||||
void addBanMessage(const QString &msg);
|
||||
|
||||
private:
|
||||
Ui::ExecutionLog *ui;
|
||||
Ui::ExecutionLog *ui;
|
||||
|
||||
LogListWidget *m_logList;
|
||||
LogListWidget *m_banList;
|
||||
int m_maxLines;
|
||||
};
|
||||
|
||||
#endif // EXECUTIONLOG_H
|
||||
|
@ -22,33 +22,17 @@
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<widget class="QWidget" name="tabGeneral">
|
||||
<attribute name="title">
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="logList">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<layout class="QVBoxLayout"/>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<widget class="QWidget" name="tabBan">
|
||||
<attribute name="title">
|
||||
<string>Blocked IPs</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="banList">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<layout class="QVBoxLayout" name="_2"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
89
src/loglistwidget.cpp
Normal file
89
src/loglistwidget.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2011 Christophe Dumez
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
#include <QKeyEvent>
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QListWidgetItem>
|
||||
#include <QLabel>
|
||||
#include <QRegExp>
|
||||
#include <QAction>
|
||||
#include "loglistwidget.h"
|
||||
#include "iconprovider.h"
|
||||
|
||||
LogListWidget::LogListWidget(int max_lines, QWidget *parent) :
|
||||
QListWidget(parent),
|
||||
m_maxLines(max_lines)
|
||||
{
|
||||
// Allow multiple selections
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
// Context menu
|
||||
QAction *copyAct = new QAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy"), this);
|
||||
connect(copyAct, SIGNAL(triggered()), SLOT(copySelection()));
|
||||
addAction(copyAct);
|
||||
setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
}
|
||||
|
||||
void LogListWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->matches(QKeySequence::Copy)) {
|
||||
copySelection();
|
||||
return;
|
||||
}
|
||||
if (event->matches(QKeySequence::SelectAll)) {
|
||||
selectAll();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void LogListWidget::appendLine(const QString &line)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(this);
|
||||
// We need to use QLabel here to support rich text
|
||||
QLabel *lbl = new QLabel(line);
|
||||
lbl->setContentsMargins(4, 2, 4, 2);
|
||||
item->setSizeHint(lbl->sizeHint());
|
||||
insertItem(0, item);
|
||||
setItemWidget(item, lbl);
|
||||
const int nbLines = count();
|
||||
// Limit log size
|
||||
if(nbLines > m_maxLines)
|
||||
delete takeItem(nbLines - 1);
|
||||
}
|
||||
|
||||
void LogListWidget::copySelection()
|
||||
{
|
||||
static QRegExp html_tag("<[^>]+>");
|
||||
QList<QListWidgetItem*> items = selectedItems();
|
||||
QStringList strings;
|
||||
foreach(QListWidgetItem* it, items)
|
||||
strings << static_cast<QLabel*>(itemWidget(it))->text().replace(html_tag, "");
|
||||
|
||||
QApplication::clipboard()->setText(strings.join("\n"));
|
||||
}
|
60
src/loglistwidget.h
Normal file
60
src/loglistwidget.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2011 Christophe Dumez
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
#ifndef LOGLISTWIDGET_H
|
||||
#define LOGLISTWIDGET_H
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QKeyEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class LogListWidget : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LogListWidget(int max_lines = 100, QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void appendLine(const QString &line);
|
||||
|
||||
protected slots:
|
||||
void copySelection();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
private:
|
||||
int m_maxLines;
|
||||
|
||||
};
|
||||
|
||||
#endif // LOGLISTWIDGET_H
|
11
src/src.pro
11
src/src.pro
@ -102,14 +102,15 @@ HEADERS += misc.h \
|
||||
scannedfoldersmodel.h \
|
||||
qinisettings.h \
|
||||
smtp.h \
|
||||
dnsupdater.h
|
||||
dnsupdater.h
|
||||
|
||||
|
||||
SOURCES += main.cpp \
|
||||
downloadthread.cpp \
|
||||
scannedfoldersmodel.cpp \
|
||||
misc.cpp \
|
||||
smtp.cpp \
|
||||
dnsupdater.cpp
|
||||
dnsupdater.cpp
|
||||
|
||||
nox {
|
||||
HEADERS += headlessloader.h
|
||||
@ -135,7 +136,8 @@ nox {
|
||||
torrentimportdlg.h \
|
||||
executionlog.h \
|
||||
iconprovider.h \
|
||||
updownratiodlg.h
|
||||
updownratiodlg.h \
|
||||
loglistwidget.h
|
||||
|
||||
SOURCES += mainwindow.cpp \
|
||||
ico.cpp \
|
||||
@ -146,7 +148,8 @@ nox {
|
||||
executionlog.cpp \
|
||||
previewselect.cpp \
|
||||
iconprovider.cpp \
|
||||
updownratiodlg.cpp
|
||||
updownratiodlg.cpp \
|
||||
loglistwidget.cpp
|
||||
|
||||
win32 {
|
||||
HEADERS += programupdater.h
|
||||
|
Loading…
x
Reference in New Issue
Block a user