Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/kget/CMakeLists.txt b/kget/CMakeLists.txt
- index 3b2fae6..a634ddd 100644
- --- a/kget/CMakeLists.txt
- +++ b/kget/CMakeLists.txt
- @@ -169,6 +169,8 @@ install(TARGETS kgetcore ${INSTALL_TARGETS_DEFAULT_ARGS})
- # kget
- set(kget_SRCS ${kget_adaptor_SRCS} ${kget_transfer_adaptor_SRCS}
- + conf/autopastemodel.cpp
- + conf/advancedpreferences.cpp
- conf/dlgwebinterface.cpp
- conf/preferencesdialog.cpp
- conf/transfersgrouptree.cpp
- diff --git a/kget/conf/advancedpreferences.cpp b/kget/conf/advancedpreferences.cpp
- new file mode 100644
- index 0000000..d17b357
- --- /dev/null
- +++ b/kget/conf/advancedpreferences.cpp
- @@ -0,0 +1,157 @@
- +/***************************************************************************
- +* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
- +* *
- +* 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 . *
- +***************************************************************************/
- +
- +#include "advancedpreferences.h"
- +#include "autopastemodel.h"
- +#include "settings.h"
- +#include "core/kget.h"
- +#include "core/transferhistorystore.h"
- +
- +#include <KConfigDialog>
- +
- +AdvancedPreferences::AdvancedPreferences(KConfigDialog *parent, Qt::WindowFlags f)
- + : QWidget(parent, f)
- +{
- + ui.setupUi(this);
- +
- + //AutoPaste stuff
- + ui.autoPasteType->addItem(KIcon("list-add"), i18n("Include"), AutoPasteModel::Include);
- + ui.autoPasteType->addItem(KIcon("list-remove"), i18n("Exclude"), AutoPasteModel::Exclude);
- +
- + ui.autoPastePatternSyntax->addItem(i18n("Escape sequences"), AutoPasteModel::Wildcard);
- + ui.autoPastePatternSyntax->addItem(i18n("Regular expression"), AutoPasteModel::RegExp);
- +
- + ui.autoPasteAdd->setGuiItem(KStandardGuiItem::add());
- + ui.autoPasteRemove->setGuiItem(KStandardGuiItem::remove());
- + ui.autoPasteIncrease->setIcon(KIcon("arrow-up"));
- + ui.autoPasteDecrease->setIcon(KIcon("arrow-down"));
- +
- +
- + // history backend entries
- + ui.kcfg_HistoryBackend->addItem(i18n("Xml"), QVariant(TransferHistoryStore::Xml));
- +#ifdef HAVE_SQLITE
- + ui.kcfg_HistoryBackend->addItem(i18n("Sqlite"), QVariant(TransferHistoryStore::SQLite));
- +#endif
- +#ifdef HAVE_NEPOMUK
- + ui.kcfg_HistoryBackend->addItem(i18n("Nepomuk"), QVariant(TransferHistoryStore::Nepomuk));
- +#endif
- +
- +#ifdef HAVE_KWORKSPACE
- + ui.kcfg_AfterFinishAction->addItem(i18n("Turn Off Computer"), QVariant(KGet::Shutdown));
- + ui.kcfg_AfterFinishAction->addItem(i18n("Hibernate Computer"), QVariant(KGet::Hibernate));
- + ui.kcfg_AfterFinishAction->addItem(i18n("Suspend Computer"), QVariant(KGet::Suspend));
- +#endif
- +
- + m_model = new AutoPasteModel(this);
- + m_model->load();
- + ui.autoPasteList->setModel(m_model);
- + AutoPasteDelegate *delegate = new AutoPasteDelegate(ui.autoPasteType->model(), ui.autoPastePatternSyntax->model(), this);
- + ui.autoPasteList->setItemDelegate(delegate);
- +
- + QByteArray loadedState = QByteArray::fromBase64(Settings::autoPasteHeaderState().toAscii());
- + if (Settings::autoPasteHeaderState().isEmpty()) {
- + ui.autoPasteList->resizeColumnToContents(AutoPasteModel::Type);
- + } else if (!loadedState.isNull()) {
- + ui.autoPasteList->header()->restoreState(loadedState);
- + }
- +
- + connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
- + connect(ui.autoPasteList->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateButtons()));
- + connect(ui.autoPastePattern, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateButtons()));
- + connect(ui.autoPastePattern, SIGNAL(returnPressed(QString)), this, SLOT(slotAddItem()));
- + connect(ui.autoPasteAdd, SIGNAL(clicked()), this, SLOT(slotAddItem()));
- + connect(ui.autoPasteRemove, SIGNAL(clicked()), this, SLOT(slotRemoveItem()));
- + connect(ui.autoPasteIncrease, SIGNAL(clicked()), this, SLOT(slotIncreasePriority()));
- + connect(ui.autoPasteDecrease, SIGNAL(clicked()), this, SLOT(slotDecreasePriority()));
- + connect(parent, SIGNAL(rejected()), m_model, SLOT(load()));
- + connect(parent, SIGNAL(accepted()), m_model, SLOT(save()));
- + connect(parent, SIGNAL(defaultClicked()), m_model, SLOT(resetDefaults()));
- +
- + slotUpdateButtons();
- +}
- +
- +AdvancedPreferences::~AdvancedPreferences()
- +{
- +}
- +
- +void AdvancedPreferences::slotUpdateButtons()
- +{
- + ui.autoPasteAdd->setEnabled(!ui.autoPastePattern->text().isEmpty());
- + ui.autoPasteRemove->setEnabled(ui.autoPasteList->selectionModel()->hasSelection());
- +
- + const QModelIndex index = ui.autoPasteList->currentIndex();
- + bool up = false;
- + bool down = false;
- + const bool indexValid = index.isValid() && (ui.autoPasteList->selectionModel()->selectedRows().count() == 1);
- + if (indexValid) {
- + if (index.row() > 0) {
- + up = true;
- + }
- + if (m_model->rowCount() > (index.row() + 1)) {
- + down = true;
- + }
- + }
- + ui.autoPasteIncrease->setEnabled(up);
- + ui.autoPasteDecrease->setEnabled(down);
- +}
- +
- +void AdvancedPreferences::slotAddItem()
- +{
- + const QString pattern = ui.autoPastePattern->text();
- + if (pattern.isEmpty()) {
- + return;
- + }
- +
- + AutoPasteModel::TypeData type = static_cast<AutoPasteModel::TypeData>(ui.autoPasteType->itemData(ui.autoPasteType->currentIndex()).toInt());
- + AutoPasteModel::PatternSyntaxData syntax = static_cast<AutoPasteModel::PatternSyntaxData>(ui.autoPastePatternSyntax->itemData(ui.autoPastePatternSyntax->currentIndex()).toInt());
- + m_model->addItem(type, syntax, pattern);
- +
- + ui.autoPastePattern->clear();
- + ui.autoPastePattern->setFocus();
- + emit changed();
- +}
- +
- +void AdvancedPreferences::slotRemoveItem()
- +{
- + QItemSelectionModel *selection = ui.autoPasteList->selectionModel();
- + if (selection->hasSelection()) {
- + while (selection->selectedRows().count()) {
- + const QModelIndex index = selection->selectedRows().first();
- + m_model->removeRow(index.row());
- + }
- + emit changed();
- + }
- +}
- +
- +void AdvancedPreferences::slotIncreasePriority()
- +{
- + const int row = ui.autoPasteList->currentIndex().row();
- + m_model->moveItem(row, row - 1);
- + slotUpdateButtons();
- + emit changed();
- +}
- +
- +void AdvancedPreferences::slotDecreasePriority()
- +{
- + const int row = ui.autoPasteList->currentIndex().row();
- + m_model->moveItem(row, row + 2);
- + slotUpdateButtons();
- + emit changed();
- +}
- +
- diff --git a/kget/conf/advancedpreferences.h b/kget/conf/advancedpreferences.h
- new file mode 100644
- index 0000000..e900099
- --- /dev/null
- +++ b/kget/conf/advancedpreferences.h
- @@ -0,0 +1,57 @@
- +/***************************************************************************
- +* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
- +* *
- +* 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 . *
- +***************************************************************************/
- +
- +#ifndef ADVANCEDPREFERENCES
- +#define ADVANCEDPREFERENCES
- +
- +#include <QtGui/QWidget>
- +
- +#include "ui_dlgadvanced.h"
- +
- +class AutoPasteModel;
- +class KConfigDialog;
- +
- +class AdvancedPreferences : public QWidget
- +{
- + Q_OBJECT
- +
- + public:
- + explicit AdvancedPreferences(KConfigDialog *parent, Qt::WindowFlags f = 0);
- + ~AdvancedPreferences();
- +
- + private slots:
- + void slotUpdateButtons();
- + void slotAddItem();
- + void slotRemoveItem();
- + void slotIncreasePriority();
- + void slotDecreasePriority();
- +
- + signals:
- + /**
- + * Emitted whenever something changes
- + */
- + void changed();
- +
- + private:
- + Ui::DlgAdvanced ui;
- + AutoPasteModel *m_model;
- +};
- +
- +#endif
- +
- diff --git a/kget/conf/autopastemodel.cpp b/kget/conf/autopastemodel.cpp
- new file mode 100644
- index 0000000..833d5d0
- --- /dev/null
- +++ b/kget/conf/autopastemodel.cpp
- @@ -0,0 +1,340 @@
- +/***************************************************************************
- +* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
- +* *
- +* 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 . *
- +***************************************************************************/
- +
- +#include "autopastemodel.h"
- +#include "settings.h"
- +
- +#include <KComboBox>
- +#include <KIcon>
- +#include <KLineEdit>
- +#include <KLocale>
- +
- +AutoPasteDelegate::AutoPasteDelegate(QAbstractItemModel *types, QAbstractItemModel *syntaxes, QObject *parent)
- + : QStyledItemDelegate(parent),
- + m_types(types),
- + m_syntaxes(syntaxes)
- +{
- +}
- +
- +QWidget *AutoPasteDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
- +{
- + Q_UNUSED(option)
- +
- + if (!index.isValid()) {
- + return 0;
- + }
- +
- + switch(index.column()) {
- + case AutoPasteModel::Type: {
- + KComboBox *types = new KComboBox(parent);
- + types->setModel(m_types);
- + return types;
- + }
- + case AutoPasteModel::Pattern: {
- + KLineEdit *pattern = new KLineEdit(parent);
- + return pattern;
- + }
- + case AutoPasteModel::PatternSyntax: {
- + KComboBox *syntaxes = new KComboBox(parent);
- + syntaxes->setModel(m_syntaxes);
- + return syntaxes;
- + }
- + default:
- + return 0;
- + }
- +}
- +
- +void AutoPasteDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
- +{
- + if (!index.isValid() || !editor) {
- + return;
- + }
- +
- + switch (index.column()) {
- + case AutoPasteModel::Type: {
- + KComboBox *type = static_cast<KComboBox*>(editor);
- + const int row = type->findData(index.data(Qt::EditRole));
- + type->setCurrentIndex(row);
- + break;
- + }
- + case AutoPasteModel::Pattern: {
- + KLineEdit *line = static_cast<KLineEdit*>(editor);
- + line->setText(index.data(Qt::EditRole).toString());
- + break;
- + }
- + case AutoPasteModel::PatternSyntax: {
- + KComboBox *syntax = static_cast<KComboBox*>(editor);
- + const int row = syntax->findData(index.data(Qt::EditRole));
- + syntax->setCurrentIndex(row);
- + break;
- + }
- + default:
- + break;
- + }
- +}
- +
- +void AutoPasteDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
- +{
- + if (!index.isValid() || !editor || !model) {
- + return;
- + }
- +
- + switch (index.column()) {
- + case AutoPasteModel::Type: {
- + KComboBox *typeBox = static_cast<KComboBox*>(editor);
- + const int type = typeBox->itemData(typeBox->currentIndex()).toInt();
- + model->setData(index, type);
- + break;
- + }
- + case AutoPasteModel::Pattern: {
- + KLineEdit *line = static_cast<KLineEdit*>(editor);
- + const QString text = line->text();
- + if (!text.isEmpty()) {
- + model->setData(index, text);
- + }
- + break;
- + }
- + case AutoPasteModel::PatternSyntax: {
- + KComboBox *syntaxBox = static_cast<KComboBox*>(editor);
- + const int syntax = syntaxBox->itemData(syntaxBox->currentIndex()).toInt();
- + model->setData(index, syntax);
- + break;
- + }
- + default:
- + break;
- + }
- +}
- +//TODO needed??
- +void AutoPasteDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
- +{
- + Q_UNUSED(index)
- + editor->setGeometry(option.rect);
- +}
- +//TODO needed??
- +QSize AutoPasteDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
- +{
- + //make the sizeHint a little bit nicer to have more beautiful editors
- + QSize hint;
- + hint.setWidth(QStyledItemDelegate::sizeHint(option, index).width());
- + hint.setHeight(option.fontMetrics.height() + 7);
- + return hint;
- +}
- +
- +AutoPasteModel::AutoPasteModel(QObject *parent)
- + : QAbstractTableModel(parent)
- +{
- +}
- +
- +AutoPasteModel::~AutoPasteModel()
- +{
- +}
- +
- +int AutoPasteModel::rowCount(const QModelIndex &index) const
- +{
- + if (!index.isValid()) {
- + return m_data.count();
- + }
- +
- + return 0;
- +}
- +
- +int AutoPasteModel::columnCount(const QModelIndex &index) const
- +{
- + if (!index.isValid()) {
- + return 3;
- + }
- +
- + return 0;
- +}
- +
- +QVariant AutoPasteModel::headerData(int section, Qt::Orientation orientation, int role) const
- +{
- + if (orientation == Qt::Vertical) {
- + return QVariant();
- + }
- +
- + if (role == Qt::DisplayRole) {
- + if (section == Pattern) {
- + return i18n("Pattern");
- + } else if (section == PatternSyntax) {
- + return i18n("Syntax");
- + }
- + }
- +
- + return QVariant();
- +}
- +
- +QVariant AutoPasteModel::data(const QModelIndex &index, int role) const
- +{
- + if (!index.isValid()) {
- + return QVariant();
- + }
- +
- + const int column = index.column();
- + const int row = index.row();
- +
- + if (column == Type) {
- + if (role == Qt::DecorationRole) {
- + return (m_data[row].type == Include ? KIcon("list-add") : KIcon("list-remove"));
- + } else if ((role == Qt::UserRole) || (role == Qt::EditRole)) {
- + return m_data[row].type;
- + }
- + } else if (column == Pattern) {
- + if ((role == Qt::DisplayRole) || (role == Qt::EditRole) || (role == Qt::UserRole)) {
- + return m_data[row].pattern;
- + }
- + } else if (column == PatternSyntax) {
- + if (role == Qt::DisplayRole) {
- + return (m_data[row].syntax == Wildcard ? i18n("Escape sequences") : i18n("Regular expression"));
- + } else if ((role == Qt::UserRole) || (role == Qt::EditRole)) {
- + return m_data[row].syntax;
- + }
- + }
- +
- + return QVariant();
- +}
- +
- +Qt::ItemFlags AutoPasteModel::flags(const QModelIndex &index) const
- +{
- + Q_UNUSED(index)
- +
- + return (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
- +}
- +
- +bool AutoPasteModel::setData(const QModelIndex &index, const QVariant &value, int role)
- +{
- + const int row = index.row();
- + const int column = index.column();
- + bool changed = false;
- +
- + if (role == Qt::EditRole) {
- + if (column == Type) {
- + m_data[row].type = static_cast<TypeData>(value.toInt());
- + changed = true;
- + } else if (column == Pattern) {
- + m_data[row].pattern = value.toString();
- + changed = true;
- + } else if (column == PatternSyntax) {
- + m_data[row].syntax = static_cast<PatternSyntaxData>(value.toInt());
- + changed = true;
- + }
- + }
- +
- + if (changed) {
- + emit dataChanged(index, index);
- + }
- +
- + return changed;
- +}
- +
- +bool AutoPasteModel::removeRows(int row, int count, const QModelIndex &parent)
- +{
- + if (parent.isValid() || (row < 0) || (count < 1) || (row + count > rowCount())) {
- + return false;
- + }
- +
- + beginRemoveRows(parent, row, row + count - 1);
- + while (count) {
- + m_data.removeAt(row);
- + --count;
- + }
- + endRemoveRows();
- +
- + return true;
- +}
- +
- +void AutoPasteModel::addItem(TypeData dataType, PatternSyntaxData patternSyntax, const QString &pattern)
- +{
- + addItems(QList<int>() << dataType, QList<int>() << patternSyntax, QStringList() << pattern);
- +}
- +
- +void AutoPasteModel::addItems(const QList<int> &dataTypes, const QList<int> patternSyntaxes, const QStringList &patterns)
- +{
- + const int row = rowCount();
- + const int numItems = patterns.count();
- + beginInsertRows(QModelIndex(), row, row + numItems - 1);
- +
- + for (int i = 0; i < numItems; ++i) {
- + Data data;
- + data.type = static_cast<TypeData>(dataTypes[i]);
- + data.pattern = patterns[i];
- + data.syntax = static_cast<PatternSyntaxData>(patternSyntaxes[i]);
- + m_data.append(data);
- + }
- +
- + endInsertRows();
- +}
- +
- +bool AutoPasteModel::moveItem(int sourceRow, int destinationRow)
- +{
- + if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow, QModelIndex(), destinationRow)) {
- + return false;
- + }
- +
- + //beginMoveRows asks for different data, than QList::move does, see the 4.7 docs
- + if (sourceRow + 2 == destinationRow) {
- + --destinationRow;
- + }
- + m_data.move(sourceRow, destinationRow);
- + endMoveRows();
- +
- + return true;
- +}
- +
- +void AutoPasteModel::load()
- +{
- + //remove all old items if there are any
- + if (rowCount()) {
- + beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
- + m_data.clear();
- + endRemoveRows();
- + }
- + addItems(Settings::autoPasteTypes(), Settings::autoPastePatternSyntaxes(), Settings::autoPastePatterns());
- +}
- +
- +void AutoPasteModel::save()
- +{
- + QList<int> types;
- + QList<int> syntaxes;
- + QStringList patterns;
- + foreach (const Data &data, m_data) {
- + types << data.type;
- + syntaxes << data.syntax;
- + patterns << data.pattern;
- + }
- +
- + Settings::self()->setAutoPasteTypes(types);
- + Settings::self()->setAutoPastePatternSyntaxes(syntaxes);
- + Settings::self()->setAutoPastePatterns(patterns);
- + Settings::self()->writeConfig();
- +}
- +
- +void AutoPasteModel::resetDefaults()
- +{
- + QStringList names = QStringList() << "AutoPastePatterns" << "AutoPasteTypes" << "AutoPastePatternSyntaxes";
- + foreach (const QString &name, names) {
- + KConfigSkeletonItem *item = Settings::self()->findItem(name);
- + if (item) {
- + item->readDefault(Settings::self()->config());
- + }
- + }
- +
- + load();
- +}
- +
- diff --git a/kget/conf/autopastemodel.h b/kget/conf/autopastemodel.h
- new file mode 100644
- index 0000000..b7fb18a
- --- /dev/null
- +++ b/kget/conf/autopastemodel.h
- @@ -0,0 +1,123 @@
- +/***************************************************************************
- +* Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
- +* *
- +* 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 . *
- +***************************************************************************/
- +
- +#ifndef AUTOPASTEMODEL
- +#define AUTOPASTEMODEL
- +
- +#include <QtCore/QAbstractTableModel>
- +#include <QtGui/QStyledItemDelegate>
- +
- +class AutoPasteDelegate : public QStyledItemDelegate
- +{
- + Q_OBJECT
- +
- + public:
- + AutoPasteDelegate(QAbstractItemModel *types, QAbstractItemModel *syntaxes, QObject *parent = 0);
- +
- + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
- + void setEditorData(QWidget *editor, const QModelIndex &index) const;
- + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
- + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
- + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
- +
- + private:
- + QAbstractItemModel *m_types;
- + QAbstractItemModel *m_syntaxes;
- +};
- +
- +class AutoPasteModel : public QAbstractTableModel
- +{
- + Q_OBJECT
- +
- + public:
- + enum DataType {
- + Type = 0,
- + Pattern,
- + PatternSyntax
- + };
- + enum TypeData {
- + Include = 0,
- + Exclude
- + };
- + enum PatternSyntaxData {
- + Wildcard = 0,
- + RegExp
- + };
- +
- + explicit AutoPasteModel(QObject *parent = 0);
- + ~AutoPasteModel();
- +
- + int rowCount(const QModelIndex &index = QModelIndex()) const;
- + int columnCount(const QModelIndex &index = QModelIndex()) const;
- + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
- + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- + Qt::ItemFlags flags(const QModelIndex &index) const;
- + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
- + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
- +
- + /**
- + * Adds an an item
- + * @note do not use this for loading data
- + * @see load()
- + */
- + void addItem(TypeData dataType, PatternSyntaxData patternSyntax, const QString &pattern);
- +
- + /**
- + * Moves an item to a new position
- + * @param sourceRow the current row of the selected item
- + * @param destinationRow is the new row before the move,
- + * i.e. if sourceRow was not removed from the model
- + * @see QAbstractItemModel::beginMoveRows()
- + */
- + bool moveItem(int sourceRow, int destinationRow);
- +
- + public slots:
- + /**
- + * Loads the stored data
- + * @see save()
- + */
- + void load();
- +
- + /**
- + * Saves the current data
- + * @see load()
- + */
- + void save();
- +
- + /**
- + * Resets the model to the default data
- + */
- + void resetDefaults();
- +
- + private:
- + void addItems(const QList<int> &dataTypes, const QList<int> patternSyntaxes, const QStringList &patterns);
- +
- + private:
- + struct Data
- + {
- + TypeData type;
- + QString pattern;
- + PatternSyntaxData syntax;
- + };
- +
- + QList<Data> m_data;
- +};
- +
- +#endif
- +
- diff --git a/kget/conf/dlgadvanced.ui b/kget/conf/dlgadvanced.ui
- index a64df1f..2fe2572 100644
- --- a/kget/conf/dlgadvanced.ui
- +++ b/kget/conf/dlgadvanced.ui
- @@ -1,155 +1,300 @@
- -<ui version="4.0" >
- +<?xml version="1.0" encoding="UTF-8"?>
- +<ui version="4.0">
- <class>DlgAdvanced</class>
- - <widget class="QWidget" name="DlgAdvanced" >
- - <property name="geometry" >
- + <widget class="QWidget" name="DlgAdvanced">
- + <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>585</width>
- - <height>443</height>
- + <height>494</height>
- </rect>
- </property>
- - <layout class="QVBoxLayout" name="verticalLayout" >
- + <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- - <widget class="QCheckBox" name="kcfg_ExpertMode" >
- - <property name="text" >
- + <widget class="QCheckBox" name="kcfg_ExpertMode">
- + <property name="text">
- <string>Disable confirmation dialogs (less verbosity)</string>
- </property>
- </widget>
- </item>
- <item>
- - <widget class="QCheckBox" name="kcfg_EnableSystemTray" >
- - <property name="text" >
- + <widget class="QCheckBox" name="kcfg_EnableSystemTray">
- + <property name="text">
- <string>Enable system tray icon</string>
- </property>
- </widget>
- </item>
- <item>
- - <layout class="QFormLayout" name="formLayout_2" >
- - <item row="0" column="0" >
- - <widget class="QCheckBox" name="kcfg_AfterFinishActionEnabled" >
- - <property name="text" >
- - <string>Execute action after all downloads have been finished:</string>
- - </property>
- - </widget>
- - </item>
- - <item row="0" column="1" >
- - <widget class="KComboBox" name="kcfg_AfterFinishAction" >
- + <widget class="QTabWidget" name="tabWidget">
- + <property name="currentIndex">
- + <number>0</number>
- + </property>
- + <widget class="QWidget" name="tab">
- + <attribute name="title">
- + <string>Integration</string>
- + </attribute>
- + <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- - <property name="text" >
- - <string>Quit KGet</string>
- - </property>
- + <layout class="QFormLayout" name="formLayout">
- + <item row="0" column="0">
- + <widget class="QLabel" name="label_4">
- + <property name="text">
- + <string>Use as download manager for Konqueror:</string>
- + </property>
- + </widget>
- + </item>
- + <item row="0" column="1">
- + <widget class="QCheckBox" name="kcfg_KonquerorIntegration">
- + <property name="text">
- + <string/>
- + </property>
- + </widget>
- + </item>
- + <item row="1" column="0">
- + <widget class="QLabel" name="label_6">
- + <property name="text">
- + <string>Monitor clipboard for files to download:</string>
- + </property>
- + </widget>
- + </item>
- + <item row="1" column="1">
- + <widget class="QCheckBox" name="kcfg_AutoPaste">
- + <property name="text">
- + <string/>
- + </property>
- + </widget>
- + </item>
- + </layout>
- </item>
- - </widget>
- - </item>
- - <item row="1" column="0" >
- - <widget class="QLabel" name="label_2" >
- - <property name="text" >
- - <string>At startup:</string>
- - </property>
- - </widget>
- - </item>
- - <item row="1" column="1" >
- - <widget class="KComboBox" name="kcfg_StartupAction" >
- <item>
- - <property name="text" >
- - <string>Restore Download State</string>
- - </property>
- + <layout class="QHBoxLayout" name="horizontalLayout_4">
- + <item>
- + <spacer name="horizontalSpacer">
- + <property name="orientation">
- + <enum>Qt::Horizontal</enum>
- + </property>
- + <property name="sizeType">
- + <enum>QSizePolicy::Fixed</enum>
- + </property>
- + <property name="sizeHint" stdset="0">
- + <size>
- + <width>40</width>
- + <height>20</height>
- + </size>
- + </property>
- + </spacer>
- + </item>
- + <item>
- + <widget class="QWidget" name="autoPasteWidget" native="true">
- + <layout class="QFormLayout" name="formLayout_6">
- + <item row="0" column="0">
- + <widget class="QLabel" name="label_5">
- + <property name="text">
- + <string>Case insensitive:</string>
- + </property>
- + </widget>
- + </item>
- + <item row="0" column="1">
- + <widget class="QCheckBox" name="kcfg_AutoPasteCaseInsensitive">
- + <property name="text">
- + <string/>
- + </property>
- + </widget>
- + </item>
- + <item row="2" column="0" colspan="2">
- + <layout class="QHBoxLayout" name="horizontalLayout_2">
- + <item>
- + <widget class="QTreeView" name="autoPasteList">
- + <property name="selectionMode">
- + <enum>QAbstractItemView::ExtendedSelection</enum>
- + </property>
- + <property name="rootIsDecorated">
- + <bool>false</bool>
- + </property>
- + <property name="uniformRowHeights">
- + <bool>true</bool>
- + </property>
- + </widget>
- + </item>
- + <item>
- + <layout class="QVBoxLayout" name="verticalLayout_4">
- + <item>
- + <widget class="KPushButton" name="autoPasteAdd"/>
- + </item>
- + <item>
- + <widget class="KPushButton" name="autoPasteRemove"/>
- + </item>
- + <item>
- + <widget class="KPushButton" name="autoPasteIncrease">
- + <property name="text">
- + <string>Increase Priority</string>
- + </property>
- + </widget>
- + </item>
- + <item>
- + <widget class="KPushButton" name="autoPasteDecrease">
- + <property name="text">
- + <string>Decrease Priority</string>
- + </property>
- + </widget>
- + </item>
- + <item>
- + <spacer name="verticalSpacer">
- + <property name="orientation">
- + <enum>Qt::Vertical</enum>
- + </property>
- + <property name="sizeHint" stdset="0">
- + <size>
- + <width>20</width>
- + <height>40</height>
- + </size>
- + </property>
- + </spacer>
- + </item>
- + </layout>
- + </item>
- + </layout>
- + </item>
- + <item row="1" column="0" colspan="2">
- + <layout class="QHBoxLayout" name="horizontalLayout">
- + <item>
- + <widget class="KComboBox" name="autoPasteType"/>
- + </item>
- + <item>
- + <widget class="KComboBox" name="autoPastePatternSyntax"/>
- + </item>
- + <item>
- + <widget class="KLineEdit" name="autoPastePattern">
- + <property name="trapEnterKeyEvent" stdset="0">
- + <bool>true</bool>
- + </property>
- + <property name="showClearButton" stdset="0">
- + <bool>true</bool>
- + </property>
- + </widget>
- + </item>
- + </layout>
- + </item>
- + </layout>
- + </widget>
- + </item>
- + </layout>
- </item>
- - <item>
- - <property name="text" >
- - <string>Start All Downloads</string>
- - </property>
- + </layout>
- + </widget>
- + <widget class="QWidget" name="tab_4">
- + <attribute name="title">
- + <string>Actions</string>
- + </attribute>
- + <layout class="QFormLayout" name="formLayout_5">
- + <item row="1" column="0">
- + <widget class="QLabel" name="label_2">
- + <property name="text">
- + <string>At startup:</string>
- + </property>
- + </widget>
- </item>
- - <item>
- - <property name="text" >
- - <string>Stop All Downloads</string>
- - </property>
- + <item row="1" column="1">
- + <widget class="KComboBox" name="kcfg_StartupAction">
- + <item>
- + <property name="text">
- + <string>Restore Download State</string>
- + </property>
- + </item>
- + <item>
- + <property name="text">
- + <string>Start All Downloads</string>
- + </property>
- + </item>
- + <item>
- + <property name="text">
- + <string>Stop All Downloads</string>
- + </property>
- + </item>
- + </widget>
- </item>
- - </widget>
- - </item>
- - </layout>
- - </item>
- - <item>
- - <widget class="QGroupBox" name="groupBox" >
- - <property name="title" >
- - <string>History</string>
- - </property>
- - <layout class="QFormLayout" name="formLayout" >
- - <item row="0" column="0" >
- - <widget class="QLabel" name="label" >
- - <property name="text" >
- - <string>History backend:</string>
- - </property>
- - </widget>
- - </item>
- - <item row="0" column="1" >
- - <widget class="KComboBox" name="kcfg_HistoryBackend" />
- - </item>
- - </layout>
- - </widget>
- - </item>
- - <item>
- - <widget class="QGroupBox" name="groupBox4" >
- - <property name="title" >
- - <string>Integration</string>
- - </property>
- - <layout class="QVBoxLayout" >
- - <item>
- - <widget class="QCheckBox" name="kcfg_KonquerorIntegration" >
- - <property name="text" >
- - <string>Use as download manager for Konqueror</string>
- - </property>
- - </widget>
- - </item>
- - <item>
- - <widget class="QCheckBox" name="kcfg_AutoPaste" >
- - <property name="text" >
- - <string>Monitor clipboard for files to download</string>
- - </property>
- - </widget>
- - </item>
- - </layout>
- - </widget>
- - </item>
- - <item>
- - <widget class="QGroupBox" name="kcfg_EnableKUIServerIntegration" >
- - <property name="title" >
- - <string>Enable KDE global progress tracking</string>
- - </property>
- - <property name="checkable" >
- - <bool>true</bool>
- - </property>
- - <property name="checked" >
- - <bool>false</bool>
- - </property>
- - <layout class="QVBoxLayout" >
- - <item>
- - <widget class="QRadioButton" name="kcfg_ExportSingleTransfer" >
- - <property name="text" >
- - <string>Show every single download </string>
- - </property>
- - </widget>
- - </item>
- - <item>
- - <widget class="QRadioButton" name="kcfg_ExportGlobalJob" >
- - <property name="text" >
- - <string>Show overall progress</string>
- - </property>
- - </widget>
- - </item>
- - </layout>
- + <item row="0" column="0">
- + <widget class="QCheckBox" name="kcfg_AfterFinishActionEnabled">
- + <property name="text">
- + <string>Execute action after all downloads have been finished:</string>
- + </property>
- + </widget>
- + </item>
- + <item row="0" column="1">
- + <widget class="KComboBox" name="kcfg_AfterFinishAction">
- + <item>
- + <property name="text">
- + <string>Quit KGet</string>
- + </property>
- + </item>
- + </widget>
- + </item>
- + </layout>
- + </widget>
- + <widget class="QWidget" name="tab_2">
- + <attribute name="title">
- + <string>History</string>
- + </attribute>
- + <layout class="QFormLayout" name="formLayout_3">
- + <item row="0" column="0">
- + <widget class="QLabel" name="label">
- + <property name="text">
- + <string>History backend:</string>
- + </property>
- + </widget>
- + </item>
- + <item row="0" column="1">
- + <widget class="KComboBox" name="kcfg_HistoryBackend"/>
- + </item>
- + </layout>
- + </widget>
- + <widget class="QWidget" name="tab_3">
- + <attribute name="title">
- + <string>Progress tracking</string>
- + </attribute>
- + <layout class="QFormLayout" name="formLayout_4">
- + <item row="0" column="1">
- + <widget class="QCheckBox" name="kcfg_EnableKUIServerIntegration">
- + <property name="text">
- + <string/>
- + </property>
- + </widget>
- + </item>
- + <item row="0" column="0">
- + <widget class="QLabel" name="label_3">
- + <property name="text">
- + <string>Enable KDE global progress tracking:</string>
- + </property>
- + </widget>
- + </item>
- + <item row="1" column="1">
- + <widget class="QRadioButton" name="kcfg_ExportSingleTransfer">
- + <property name="text">
- + <string>Show every single download </string>
- + </property>
- + </widget>
- + </item>
- + <item row="2" column="1">
- + <widget class="QRadioButton" name="kcfg_ExportGlobalJob">
- + <property name="text">
- + <string>Show overall progress</string>
- + </property>
- + </widget>
- + </item>
- + </layout>
- + </widget>
- </widget>
- </item>
- <item>
- <spacer>
- - <property name="orientation" >
- + <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- - <property name="sizeType" >
- + <property name="sizeType">
- <enum>QSizePolicy::Expanding</enum>
- </property>
- - <property name="sizeHint" stdset="0" >
- + <property name="sizeHint" stdset="0">
- <size>
- <width>200</width>
- <height>20</height>
- @@ -159,7 +304,17 @@
- </item>
- </layout>
- </widget>
- - <customwidgets>
- + <customwidgets>
- + <customwidget>
- + <class>KPushButton</class>
- + <extends>QPushButton</extends>
- + <header>kpushbutton.h</header>
- + </customwidget>
- + <customwidget>
- + <class>KLineEdit</class>
- + <extends>QLineEdit</extends>
- + <header>klineedit.h</header>
- + </customwidget>
- <customwidget>
- <class>KComboBox</class>
- <extends>QComboBox</extends>
- @@ -167,5 +322,70 @@
- </customwidget>
- </customwidgets>
- <resources/>
- - <connections/>
- + <connections>
- + <connection>
- + <sender>kcfg_AfterFinishActionEnabled</sender>
- + <signal>toggled(bool)</signal>
- + <receiver>kcfg_AfterFinishAction</receiver>
- + <slot>setEnabled(bool)</slot>
- + <hints>
- + <hint type="sourcelabel">
- + <x>170</x>
- + <y>70</y>
- + </hint>
- + <hint type="destinationlabel">
- + <x>379</x>
- + <y>70</y>
- + </hint>
- + </hints>
- + </connection>
- + <connection>
- + <sender>kcfg_EnableKUIServerIntegration</sender>
- + <signal>toggled(bool)</signal>
- + <receiver>kcfg_ExportSingleTransfer</receiver>
- + <slot>setEnabled(bool)</slot>
- + <hints>
- + <hint type="sourcelabel">
- + <x>29</x>
- + <y>147</y>
- + </hint>
- + <hint type="destinationlabel">
- + <x>316</x>
- + <y>182</y>
- + </hint>
- + </hints>
- + </connection>
- + <connection>
- + <sender>kcfg_EnableKUIServerIntegration</sender>
- + <signal>toggled(bool)</signal>
- + <receiver>kcfg_ExportGlobalJob</receiver>
- + <slot>setEnabled(bool)</slot>
- + <hints>
- + <hint type="sourcelabel">
- + <x>236</x>
- + <y>156</y>
- + </hint>
- + <hint type="destinationlabel">
- + <x>298</x>
- + <y>207</y>
- + </hint>
- + </hints>
- + </connection>
- + <connection>
- + <sender>kcfg_AutoPaste</sender>
- + <signal>toggled(bool)</signal>
- + <receiver>autoPasteWidget</receiver>
- + <slot>setEnabled(bool)</slot>
- + <hints>
- + <hint type="sourcelabel">
- + <x>264</x>
- + <y>126</y>
- + </hint>
- + <hint type="destinationlabel">
- + <x>314</x>
- + <y>274</y>
- + </hint>
- + </hints>
- + </connection>
- + </connections>
- </ui>
- diff --git a/kget/conf/kget.kcfg b/kget/conf/kget.kcfg
- index 220fa1a..997e1c6 100644
- --- a/kget/conf/kget.kcfg
- +++ b/kget/conf/kget.kcfg
- @@ -15,6 +15,8 @@
- </entry>
- <entry name="VerificationHeaderState" type="String">
- </entry>
- + <entry name="AutoPasteHeaderState" type="String">
- + </entry>
- <entry name="ShowMain" type="Bool">
- <default>true</default>
- </entry>
- @@ -49,6 +51,18 @@
- <entry name="AutoPaste" type="Bool">
- <default>false</default>
- </entry>
- + <entry name="AutoPasteCaseInsensitive" type="Bool">
- + <default>true</default>
- + </entry>
- + <entry name="AutoPastePatterns" type="StringList">
- + <default>*</default>
- + </entry>
- + <entry name="AutoPasteTypes" type="IntList">
- + <default>0</default>
- + </entry>
- + <entry name="AutoPastePatternSyntaxes" type="IntList">
- + <default>0</default>
- + </entry>
- <entry name="TimedDownload" type="Bool">
- <default>false</default>
- </entry>
- diff --git a/kget/conf/preferencesdialog.cpp b/kget/conf/preferencesdialog.cpp
- index 8973813..8d94802 100644
- --- a/kget/conf/preferencesdialog.cpp
- +++ b/kget/conf/preferencesdialog.cpp
- @@ -8,13 +8,12 @@
- */
- #include "preferencesdialog.h"
- -#include "core/kget.h"
- -#include "core/transferhistorystore.h"
- #include "ui_dlgappearance.h"
- #include "ui_dlgnetwork.h"
- #include "dlgwebinterface.h"
- +#include "advancedpreferences.h"
- #include "transfersgroupwidget.h"
- #include "pluginselector.h"
- #include "verificationpreferences.h"
- @@ -29,7 +28,8 @@ PreferencesDialog::PreferencesDialog(QWidget * parent, KConfigSkeleton * skeleto
- TransfersGroupWidget *groups = new TransfersGroupWidget(this);
- DlgWebinterface *webinterface = new DlgWebinterface(this);
- QWidget *network = new QWidget(this);
- - QWidget *advanced = new QWidget(this);
- + AdvancedPreferences *advanced = new AdvancedPreferences(this);
- + connect(advanced, SIGNAL(changed()), SLOT(enableApplyButton()));
- VerificationPreferences *verification = new VerificationPreferences(this);
- connect(verification, SIGNAL(changed()), SLOT(enableApplyButton()));
- PluginSelector * pluginSelector = new PluginSelector(this);
- @@ -40,27 +40,6 @@ PreferencesDialog::PreferencesDialog(QWidget * parent, KConfigSkeleton * skeleto
- dlgApp.setupUi(appearance);
- dlgNet.setupUi(network);
- - dlgAdv.setupUi(advanced);
- -
- - // history backend entries
- - dlgAdv.kcfg_HistoryBackend->addItem(i18n("Xml"), QVariant(TransferHistoryStore::Xml));
- -#ifdef HAVE_SQLITE
- - dlgAdv.kcfg_HistoryBackend->addItem(i18n("Sqlite"), QVariant(TransferHistoryStore::SQLite));
- -#endif
- -#ifdef HAVE_NEPOMUK
- - dlgAdv.kcfg_HistoryBackend->addItem(i18n("Nepomuk"), QVariant(TransferHistoryStore::Nepomuk));
- -#endif
- -
- -#ifdef HAVE_KWORKSPACE
- - dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Turn Off Computer"), QVariant(KGet::Shutdown));
- - dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Hibernate Computer"), QVariant(KGet::Hibernate));
- - dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Suspend Computer"), QVariant(KGet::Suspend));
- -#endif
- -
- - // enable or disable the AfterFinishAction depends on the AfterFinishActionEnabled checkbox state
- - dlgAdv.kcfg_AfterFinishAction->setEnabled(dlgAdv.kcfg_AfterFinishActionEnabled->checkState () == Qt::Checked);
- - connect(dlgAdv.kcfg_AfterFinishActionEnabled, SIGNAL(stateChanged(int)),
- - SLOT(slotToggleAfterFinishAction(int)));
- // TODO: remove the following lines as soon as these features are ready
- dlgNet.lb_per_transfer->setVisible(false);
- @@ -91,7 +70,3 @@ void PreferencesDialog::enableApplyButton()
- enableButtonApply(true);
- }
- -void PreferencesDialog::slotToggleAfterFinishAction(int state)
- -{
- - dlgAdv.kcfg_AfterFinishAction->setEnabled(state == Qt::Checked);
- -}
- diff --git a/kget/conf/preferencesdialog.h b/kget/conf/preferencesdialog.h
- index aaa3054..8acc3fb 100644
- --- a/kget/conf/preferencesdialog.h
- +++ b/kget/conf/preferencesdialog.h
- @@ -10,14 +10,8 @@
- #ifndef PREFERENCESDIALOG_H
- #define PREFERENCESDIALOG_H
- -#include "ui_dlgadvanced.h"
- -
- #include <kconfigdialog.h>
- -class QWidget;
- -class KConfigSkeleton;
- -class KTabWidget;
- -
- class PreferencesDialog : public KConfigDialog
- {
- Q_OBJECT
- @@ -25,12 +19,8 @@ class PreferencesDialog : public KConfigDialog
- PreferencesDialog( QWidget * parent, KConfigSkeleton * config );
- private slots:
- - void slotToggleAfterFinishAction(int state);
- void disableApplyButton();
- void enableApplyButton();
- -
- - private:
- - Ui::DlgAdvanced dlgAdv;
- };
- #endif
- diff --git a/kget/mainwindow.cpp b/kget/mainwindow.cpp
- index aa93f75..24f10db 100644
- --- a/kget/mainwindow.cpp
- +++ b/kget/mainwindow.cpp
- @@ -22,6 +22,7 @@
- #include "core/transfertreemodel.h"
- #include "core/transfertreeselectionmodel.h"
- #include "settings.h"
- +#include "conf/autopastemodel.h"
- #include "conf/preferencesdialog.h"
- #include "ui/viewscontainer.h"
- #include "ui/tray.h"
- @@ -967,7 +968,26 @@ void MainWindow::slotCheckClipboard()
- const KUrl url = KUrl(lastClipboard);
- if (url.isValid() && !url.protocol().isEmpty() && url.hasPath() && url.hasHost() && !url.isLocalFile()) {
- - KGet::addTransfer( url );
- + bool add = false;
- + const QString urlString = url.url();
- +
- + //check the combined whitelist and blacklist
- + const QList<int> types = Settings::autoPasteTypes();
- + const QList<int> syntaxes = Settings::autoPastePatternSyntaxes();
- + const QStringList patterns = Settings::autoPastePatterns();
- + const Qt::CaseSensitivity cs = (Settings::autoPasteCaseInsensitive() ? Qt::CaseInsensitive : Qt::CaseSensitive);
- + for (int i = 0; i < types.count(); ++i) {
- + const QRegExp::PatternSyntax syntax = (syntaxes[i] == AutoPasteModel::Wildcard ? QRegExp::Wildcard : QRegExp::RegExp2);
- + QRegExp rx(patterns[i], cs, syntax);//TODO case insensitivity + type
- + if (rx.exactMatch(urlString)) {
- + add = (types[i] == AutoPasteModel::Include);
- + break;
- + }
- + }
- +
- + if (add) {
- + KGet::addTransfer(url);
- + }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement