Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 48.26 KB | None | 0 0
  1. diff --git a/kget/CMakeLists.txt b/kget/CMakeLists.txt
  2. index 3b2fae6..a634ddd 100644
  3. --- a/kget/CMakeLists.txt
  4. +++ b/kget/CMakeLists.txt
  5. @@ -169,6 +169,8 @@ install(TARGETS kgetcore ${INSTALL_TARGETS_DEFAULT_ARGS})
  6.  # kget
  7.  
  8.  set(kget_SRCS ${kget_adaptor_SRCS} ${kget_transfer_adaptor_SRCS}
  9. +   conf/autopastemodel.cpp
  10. +   conf/advancedpreferences.cpp
  11.     conf/dlgwebinterface.cpp
  12.     conf/preferencesdialog.cpp
  13.     conf/transfersgrouptree.cpp
  14. diff --git a/kget/conf/advancedpreferences.cpp b/kget/conf/advancedpreferences.cpp
  15. new file mode 100644
  16. index 0000000..d17b357
  17. --- /dev/null
  18. +++ b/kget/conf/advancedpreferences.cpp
  19. @@ -0,0 +1,157 @@
  20. +/***************************************************************************
  21. +*   Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>                     *
  22. +*                                                                         *
  23. +*   This program is free software; you can redistribute it and/or modify  *
  24. +*   it under the terms of the GNU General Public License as published by  *
  25. +*   the Free Software Foundation; either version 2 of the License, or     *
  26. +*   (at your option) any later version.                                   *
  27. +*                                                                         *
  28. +*   This program is distributed in the hope that it will be useful,       *
  29. +*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  30. +*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  31. +*   GNU General Public License for more details.                          *
  32. +*                                                                         *
  33. +*   You should have received a copy of the GNU General Public License     *
  34. +*   along with this program; if not, write to the                         *
  35. +*   Free Software Foundation, Inc.,                                       *
  36. +*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  37. +***************************************************************************/
  38. +
  39. +#include "advancedpreferences.h"
  40. +#include "autopastemodel.h"
  41. +#include "settings.h"
  42. +#include "core/kget.h"
  43. +#include "core/transferhistorystore.h"
  44. +
  45. +#include <KConfigDialog>
  46. +
  47. +AdvancedPreferences::AdvancedPreferences(KConfigDialog *parent, Qt::WindowFlags f)
  48. +  : QWidget(parent, f)
  49. +{
  50. +    ui.setupUi(this);
  51. +
  52. +    //AutoPaste stuff
  53. +    ui.autoPasteType->addItem(KIcon("list-add"), i18n("Include"), AutoPasteModel::Include);
  54. +    ui.autoPasteType->addItem(KIcon("list-remove"), i18n("Exclude"), AutoPasteModel::Exclude);
  55. +
  56. +    ui.autoPastePatternSyntax->addItem(i18n("Escape sequences"), AutoPasteModel::Wildcard);
  57. +    ui.autoPastePatternSyntax->addItem(i18n("Regular expression"), AutoPasteModel::RegExp);
  58. +
  59. +    ui.autoPasteAdd->setGuiItem(KStandardGuiItem::add());
  60. +    ui.autoPasteRemove->setGuiItem(KStandardGuiItem::remove());
  61. +    ui.autoPasteIncrease->setIcon(KIcon("arrow-up"));
  62. +    ui.autoPasteDecrease->setIcon(KIcon("arrow-down"));
  63. +
  64. +
  65. +    // history backend entries
  66. +    ui.kcfg_HistoryBackend->addItem(i18n("Xml"), QVariant(TransferHistoryStore::Xml));
  67. +#ifdef HAVE_SQLITE
  68. +    ui.kcfg_HistoryBackend->addItem(i18n("Sqlite"), QVariant(TransferHistoryStore::SQLite));
  69. +#endif
  70. +#ifdef HAVE_NEPOMUK
  71. +    ui.kcfg_HistoryBackend->addItem(i18n("Nepomuk"), QVariant(TransferHistoryStore::Nepomuk));
  72. +#endif
  73. +
  74. +#ifdef HAVE_KWORKSPACE
  75. +    ui.kcfg_AfterFinishAction->addItem(i18n("Turn Off Computer"), QVariant(KGet::Shutdown));
  76. +    ui.kcfg_AfterFinishAction->addItem(i18n("Hibernate Computer"), QVariant(KGet::Hibernate));
  77. +    ui.kcfg_AfterFinishAction->addItem(i18n("Suspend Computer"), QVariant(KGet::Suspend));
  78. +#endif
  79. +
  80. +    m_model = new AutoPasteModel(this);
  81. +    m_model->load();
  82. +    ui.autoPasteList->setModel(m_model);
  83. +    AutoPasteDelegate *delegate = new AutoPasteDelegate(ui.autoPasteType->model(), ui.autoPastePatternSyntax->model(), this);
  84. +    ui.autoPasteList->setItemDelegate(delegate);
  85. +
  86. +    QByteArray loadedState = QByteArray::fromBase64(Settings::autoPasteHeaderState().toAscii());
  87. +    if (Settings::autoPasteHeaderState().isEmpty()) {
  88. +        ui.autoPasteList->resizeColumnToContents(AutoPasteModel::Type);
  89. +    } else if (!loadedState.isNull()) {
  90. +        ui.autoPasteList->header()->restoreState(loadedState);
  91. +    }
  92. +
  93. +    connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
  94. +    connect(ui.autoPasteList->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateButtons()));
  95. +    connect(ui.autoPastePattern, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateButtons()));
  96. +    connect(ui.autoPastePattern, SIGNAL(returnPressed(QString)), this, SLOT(slotAddItem()));
  97. +    connect(ui.autoPasteAdd, SIGNAL(clicked()), this, SLOT(slotAddItem()));
  98. +    connect(ui.autoPasteRemove, SIGNAL(clicked()), this, SLOT(slotRemoveItem()));
  99. +    connect(ui.autoPasteIncrease, SIGNAL(clicked()), this, SLOT(slotIncreasePriority()));
  100. +    connect(ui.autoPasteDecrease, SIGNAL(clicked()), this, SLOT(slotDecreasePriority()));
  101. +    connect(parent, SIGNAL(rejected()), m_model, SLOT(load()));
  102. +    connect(parent, SIGNAL(accepted()), m_model, SLOT(save()));
  103. +    connect(parent, SIGNAL(defaultClicked()), m_model, SLOT(resetDefaults()));
  104. +
  105. +    slotUpdateButtons();
  106. +}
  107. +
  108. +AdvancedPreferences::~AdvancedPreferences()
  109. +{
  110. +}
  111. +
  112. +void AdvancedPreferences::slotUpdateButtons()
  113. +{
  114. +    ui.autoPasteAdd->setEnabled(!ui.autoPastePattern->text().isEmpty());
  115. +    ui.autoPasteRemove->setEnabled(ui.autoPasteList->selectionModel()->hasSelection());
  116. +
  117. +    const QModelIndex index = ui.autoPasteList->currentIndex();
  118. +    bool up = false;
  119. +    bool down = false;
  120. +    const bool indexValid = index.isValid() && (ui.autoPasteList->selectionModel()->selectedRows().count() == 1);
  121. +    if (indexValid) {
  122. +        if (index.row() > 0) {
  123. +            up = true;
  124. +        }
  125. +        if (m_model->rowCount() > (index.row() + 1)) {
  126. +            down = true;
  127. +        }
  128. +    }
  129. +    ui.autoPasteIncrease->setEnabled(up);
  130. +    ui.autoPasteDecrease->setEnabled(down);
  131. +}
  132. +
  133. +void AdvancedPreferences::slotAddItem()
  134. +{
  135. +    const QString pattern = ui.autoPastePattern->text();
  136. +    if (pattern.isEmpty()) {
  137. +        return;
  138. +    }
  139. +
  140. +    AutoPasteModel::TypeData type = static_cast<AutoPasteModel::TypeData>(ui.autoPasteType->itemData(ui.autoPasteType->currentIndex()).toInt());
  141. +    AutoPasteModel::PatternSyntaxData syntax = static_cast<AutoPasteModel::PatternSyntaxData>(ui.autoPastePatternSyntax->itemData(ui.autoPastePatternSyntax->currentIndex()).toInt());
  142. +    m_model->addItem(type, syntax, pattern);
  143. +
  144. +    ui.autoPastePattern->clear();
  145. +    ui.autoPastePattern->setFocus();
  146. +    emit changed();
  147. +}
  148. +
  149. +void AdvancedPreferences::slotRemoveItem()
  150. +{
  151. +    QItemSelectionModel *selection = ui.autoPasteList->selectionModel();
  152. +    if (selection->hasSelection()) {
  153. +        while (selection->selectedRows().count()) {
  154. +            const QModelIndex index = selection->selectedRows().first();
  155. +            m_model->removeRow(index.row());
  156. +        }
  157. +        emit changed();
  158. +    }
  159. +}
  160. +
  161. +void AdvancedPreferences::slotIncreasePriority()
  162. +{
  163. +    const int row = ui.autoPasteList->currentIndex().row();
  164. +    m_model->moveItem(row, row - 1);
  165. +    slotUpdateButtons();
  166. +    emit changed();
  167. +}
  168. +
  169. +void AdvancedPreferences::slotDecreasePriority()
  170. +{
  171. +    const int row = ui.autoPasteList->currentIndex().row();
  172. +    m_model->moveItem(row, row + 2);
  173. +    slotUpdateButtons();
  174. +    emit changed();
  175. +}
  176. +
  177. diff --git a/kget/conf/advancedpreferences.h b/kget/conf/advancedpreferences.h
  178. new file mode 100644
  179. index 0000000..e900099
  180. --- /dev/null
  181. +++ b/kget/conf/advancedpreferences.h
  182. @@ -0,0 +1,57 @@
  183. +/***************************************************************************
  184. +*   Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>                     *
  185. +*                                                                         *
  186. +*   This program is free software; you can redistribute it and/or modify  *
  187. +*   it under the terms of the GNU General Public License as published by  *
  188. +*   the Free Software Foundation; either version 2 of the License, or     *
  189. +*   (at your option) any later version.                                   *
  190. +*                                                                         *
  191. +*   This program is distributed in the hope that it will be useful,       *
  192. +*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  193. +*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  194. +*   GNU General Public License for more details.                          *
  195. +*                                                                         *
  196. +*   You should have received a copy of the GNU General Public License     *
  197. +*   along with this program; if not, write to the                         *
  198. +*   Free Software Foundation, Inc.,                                       *
  199. +*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  200. +***************************************************************************/
  201. +
  202. +#ifndef ADVANCEDPREFERENCES
  203. +#define ADVANCEDPREFERENCES
  204. +
  205. +#include <QtGui/QWidget>
  206. +
  207. +#include "ui_dlgadvanced.h"
  208. +
  209. +class AutoPasteModel;
  210. +class KConfigDialog;
  211. +
  212. +class AdvancedPreferences : public QWidget
  213. +{
  214. +    Q_OBJECT
  215. +
  216. +    public:
  217. +        explicit AdvancedPreferences(KConfigDialog *parent, Qt::WindowFlags f = 0);
  218. +        ~AdvancedPreferences();
  219. +
  220. +    private slots:
  221. +        void slotUpdateButtons();
  222. +        void slotAddItem();
  223. +        void slotRemoveItem();
  224. +        void slotIncreasePriority();
  225. +        void slotDecreasePriority();
  226. +
  227. +    signals:
  228. +        /**
  229. +         * Emitted whenever something changes
  230. +         */
  231. +        void changed();
  232. +
  233. +    private:
  234. +        Ui::DlgAdvanced ui;
  235. +        AutoPasteModel *m_model;
  236. +};
  237. +
  238. +#endif
  239. +
  240. diff --git a/kget/conf/autopastemodel.cpp b/kget/conf/autopastemodel.cpp
  241. new file mode 100644
  242. index 0000000..833d5d0
  243. --- /dev/null
  244. +++ b/kget/conf/autopastemodel.cpp
  245. @@ -0,0 +1,340 @@
  246. +/***************************************************************************
  247. +*   Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>                     *
  248. +*                                                                         *
  249. +*   This program is free software; you can redistribute it and/or modify  *
  250. +*   it under the terms of the GNU General Public License as published by  *
  251. +*   the Free Software Foundation; either version 2 of the License, or     *
  252. +*   (at your option) any later version.                                   *
  253. +*                                                                         *
  254. +*   This program is distributed in the hope that it will be useful,       *
  255. +*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  256. +*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  257. +*   GNU General Public License for more details.                          *
  258. +*                                                                         *
  259. +*   You should have received a copy of the GNU General Public License     *
  260. +*   along with this program; if not, write to the                         *
  261. +*   Free Software Foundation, Inc.,                                       *
  262. +*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  263. +***************************************************************************/
  264. +
  265. +#include "autopastemodel.h"
  266. +#include "settings.h"
  267. +
  268. +#include <KComboBox>
  269. +#include <KIcon>
  270. +#include <KLineEdit>
  271. +#include <KLocale>
  272. +
  273. +AutoPasteDelegate::AutoPasteDelegate(QAbstractItemModel *types, QAbstractItemModel *syntaxes, QObject *parent)
  274. +  : QStyledItemDelegate(parent),
  275. +    m_types(types),
  276. +    m_syntaxes(syntaxes)
  277. +{
  278. +}
  279. +
  280. +QWidget *AutoPasteDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
  281. +{
  282. +    Q_UNUSED(option)
  283. +
  284. +    if (!index.isValid()) {
  285. +        return 0;
  286. +    }
  287. +
  288. +    switch(index.column()) {
  289. +        case AutoPasteModel::Type: {
  290. +            KComboBox *types = new KComboBox(parent);
  291. +            types->setModel(m_types);
  292. +            return types;
  293. +        }
  294. +        case AutoPasteModel::Pattern: {
  295. +            KLineEdit *pattern = new KLineEdit(parent);
  296. +            return pattern;
  297. +        }
  298. +        case AutoPasteModel::PatternSyntax: {
  299. +            KComboBox *syntaxes = new KComboBox(parent);
  300. +            syntaxes->setModel(m_syntaxes);
  301. +            return syntaxes;
  302. +        }
  303. +        default:
  304. +            return 0;
  305. +    }
  306. +}
  307. +
  308. +void AutoPasteDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  309. +{
  310. +    if (!index.isValid() || !editor) {
  311. +        return;
  312. +    }
  313. +
  314. +    switch (index.column()) {
  315. +        case AutoPasteModel::Type: {
  316. +            KComboBox *type = static_cast<KComboBox*>(editor);
  317. +            const int row = type->findData(index.data(Qt::EditRole));
  318. +            type->setCurrentIndex(row);
  319. +            break;
  320. +        }
  321. +        case AutoPasteModel::Pattern: {
  322. +            KLineEdit *line = static_cast<KLineEdit*>(editor);
  323. +            line->setText(index.data(Qt::EditRole).toString());
  324. +            break;
  325. +        }
  326. +        case AutoPasteModel::PatternSyntax: {
  327. +            KComboBox *syntax = static_cast<KComboBox*>(editor);
  328. +            const int row = syntax->findData(index.data(Qt::EditRole));
  329. +            syntax->setCurrentIndex(row);
  330. +            break;
  331. +        }
  332. +        default:
  333. +            break;
  334. +    }
  335. +}
  336. +
  337. +void AutoPasteDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
  338. +{
  339. +    if (!index.isValid() || !editor || !model) {
  340. +        return;
  341. +    }
  342. +
  343. +    switch (index.column()) {
  344. +        case AutoPasteModel::Type: {
  345. +            KComboBox *typeBox = static_cast<KComboBox*>(editor);
  346. +            const int type = typeBox->itemData(typeBox->currentIndex()).toInt();
  347. +            model->setData(index, type);
  348. +            break;
  349. +        }
  350. +        case AutoPasteModel::Pattern: {
  351. +            KLineEdit *line = static_cast<KLineEdit*>(editor);
  352. +            const QString text = line->text();
  353. +            if (!text.isEmpty()) {
  354. +                model->setData(index, text);
  355. +            }
  356. +            break;
  357. +        }
  358. +        case AutoPasteModel::PatternSyntax: {
  359. +            KComboBox *syntaxBox = static_cast<KComboBox*>(editor);
  360. +            const int syntax = syntaxBox->itemData(syntaxBox->currentIndex()).toInt();
  361. +            model->setData(index, syntax);
  362. +            break;
  363. +        }
  364. +        default:
  365. +            break;
  366. +    }
  367. +}
  368. +//TODO needed??
  369. +void AutoPasteDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
  370. +{
  371. +    Q_UNUSED(index)
  372. +    editor->setGeometry(option.rect);
  373. +}
  374. +//TODO needed??
  375. +QSize AutoPasteDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  376. +{
  377. +    //make the sizeHint a little bit nicer to have more beautiful editors
  378. +    QSize hint;
  379. +    hint.setWidth(QStyledItemDelegate::sizeHint(option, index).width());
  380. +    hint.setHeight(option.fontMetrics.height() + 7);
  381. +    return hint;
  382. +}
  383. +
  384. +AutoPasteModel::AutoPasteModel(QObject *parent)
  385. +  : QAbstractTableModel(parent)
  386. +{
  387. +}
  388. +
  389. +AutoPasteModel::~AutoPasteModel()
  390. +{
  391. +}
  392. +
  393. +int AutoPasteModel::rowCount(const QModelIndex &index) const
  394. +{
  395. +    if (!index.isValid()) {
  396. +        return m_data.count();
  397. +    }
  398. +
  399. +    return 0;
  400. +}
  401. +
  402. +int AutoPasteModel::columnCount(const QModelIndex &index) const
  403. +{
  404. +    if (!index.isValid()) {
  405. +        return 3;
  406. +    }
  407. +
  408. +    return 0;
  409. +}
  410. +
  411. +QVariant AutoPasteModel::headerData(int section, Qt::Orientation orientation, int role) const
  412. +{
  413. +    if (orientation == Qt::Vertical) {
  414. +        return QVariant();
  415. +    }
  416. +
  417. +    if (role == Qt::DisplayRole) {
  418. +        if (section == Pattern) {
  419. +            return i18n("Pattern");
  420. +        } else if (section == PatternSyntax) {
  421. +            return i18n("Syntax");
  422. +        }
  423. +    }
  424. +
  425. +    return QVariant();
  426. +}
  427. +
  428. +QVariant AutoPasteModel::data(const QModelIndex &index, int role) const
  429. +{
  430. +    if (!index.isValid()) {
  431. +        return QVariant();
  432. +    }
  433. +
  434. +    const int column = index.column();
  435. +    const int row = index.row();
  436. +
  437. +    if (column == Type) {
  438. +        if (role == Qt::DecorationRole) {
  439. +            return (m_data[row].type == Include ? KIcon("list-add") : KIcon("list-remove"));
  440. +        } else if ((role == Qt::UserRole) || (role == Qt::EditRole)) {
  441. +            return m_data[row].type;
  442. +        }
  443. +    } else if (column == Pattern) {
  444. +        if ((role == Qt::DisplayRole) || (role == Qt::EditRole) || (role == Qt::UserRole)) {
  445. +            return m_data[row].pattern;
  446. +        }
  447. +    } else if (column == PatternSyntax) {
  448. +        if (role == Qt::DisplayRole) {
  449. +            return (m_data[row].syntax == Wildcard ? i18n("Escape sequences") : i18n("Regular expression"));
  450. +        } else if ((role == Qt::UserRole) || (role == Qt::EditRole)) {
  451. +            return m_data[row].syntax;
  452. +        }
  453. +    }
  454. +
  455. +    return QVariant();
  456. +}
  457. +
  458. +Qt::ItemFlags AutoPasteModel::flags(const QModelIndex &index) const
  459. +{
  460. +    Q_UNUSED(index)
  461. +
  462. +    return (Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
  463. +}
  464. +
  465. +bool AutoPasteModel::setData(const QModelIndex &index, const QVariant &value, int role)
  466. +{
  467. +    const int row = index.row();
  468. +    const int column = index.column();
  469. +    bool changed = false;
  470. +
  471. +    if (role == Qt::EditRole) {
  472. +        if (column == Type) {
  473. +            m_data[row].type = static_cast<TypeData>(value.toInt());
  474. +            changed = true;
  475. +        } else if (column == Pattern) {
  476. +            m_data[row].pattern = value.toString();
  477. +            changed = true;
  478. +        } else if (column == PatternSyntax) {
  479. +            m_data[row].syntax = static_cast<PatternSyntaxData>(value.toInt());
  480. +            changed = true;
  481. +        }
  482. +    }
  483. +
  484. +    if (changed) {
  485. +        emit dataChanged(index, index);
  486. +    }
  487. +
  488. +    return changed;
  489. +}
  490. +
  491. +bool AutoPasteModel::removeRows(int row, int count, const QModelIndex &parent)
  492. +{
  493. +    if (parent.isValid() || (row < 0) || (count < 1) || (row + count > rowCount())) {
  494. +        return false;
  495. +    }
  496. +
  497. +    beginRemoveRows(parent, row, row + count - 1);
  498. +    while (count) {
  499. +        m_data.removeAt(row);
  500. +        --count;
  501. +    }
  502. +    endRemoveRows();
  503. +
  504. +    return true;
  505. +}
  506. +
  507. +void AutoPasteModel::addItem(TypeData dataType, PatternSyntaxData patternSyntax, const QString &pattern)
  508. +{
  509. +    addItems(QList<int>() << dataType, QList<int>() << patternSyntax, QStringList() << pattern);
  510. +}
  511. +
  512. +void AutoPasteModel::addItems(const QList<int> &dataTypes, const QList<int> patternSyntaxes, const QStringList &patterns)
  513. +{
  514. +    const int row = rowCount();
  515. +    const int numItems = patterns.count();
  516. +    beginInsertRows(QModelIndex(), row, row + numItems - 1);
  517. +
  518. +    for (int i = 0; i < numItems; ++i) {
  519. +        Data data;
  520. +        data.type = static_cast<TypeData>(dataTypes[i]);
  521. +        data.pattern = patterns[i];
  522. +        data.syntax = static_cast<PatternSyntaxData>(patternSyntaxes[i]);
  523. +        m_data.append(data);
  524. +    }
  525. +
  526. +    endInsertRows();
  527. +}
  528. +
  529. +bool AutoPasteModel::moveItem(int sourceRow, int destinationRow)
  530. +{
  531. +    if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow, QModelIndex(), destinationRow)) {
  532. +        return false;
  533. +    }
  534. +
  535. +    //beginMoveRows asks for different data, than QList::move does, see the 4.7 docs
  536. +    if (sourceRow + 2 == destinationRow) {
  537. +        --destinationRow;
  538. +    }
  539. +    m_data.move(sourceRow, destinationRow);
  540. +    endMoveRows();
  541. +
  542. +    return true;
  543. +}
  544. +
  545. +void AutoPasteModel::load()
  546. +{
  547. +    //remove all old items if there are any
  548. +    if (rowCount()) {
  549. +        beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
  550. +        m_data.clear();
  551. +        endRemoveRows();
  552. +    }
  553. +    addItems(Settings::autoPasteTypes(), Settings::autoPastePatternSyntaxes(), Settings::autoPastePatterns());
  554. +}
  555. +
  556. +void AutoPasteModel::save()
  557. +{
  558. +    QList<int> types;
  559. +    QList<int> syntaxes;
  560. +    QStringList patterns;
  561. +    foreach (const Data &data, m_data) {
  562. +        types << data.type;
  563. +        syntaxes << data.syntax;
  564. +        patterns << data.pattern;
  565. +    }
  566. +
  567. +    Settings::self()->setAutoPasteTypes(types);
  568. +    Settings::self()->setAutoPastePatternSyntaxes(syntaxes);
  569. +    Settings::self()->setAutoPastePatterns(patterns);
  570. +    Settings::self()->writeConfig();
  571. +}
  572. +
  573. +void AutoPasteModel::resetDefaults()
  574. +{
  575. +    QStringList names = QStringList() << "AutoPastePatterns" << "AutoPasteTypes" << "AutoPastePatternSyntaxes";
  576. +    foreach (const QString &name, names) {
  577. +        KConfigSkeletonItem *item = Settings::self()->findItem(name);
  578. +        if (item) {
  579. +            item->readDefault(Settings::self()->config());
  580. +        }
  581. +    }
  582. +
  583. +    load();
  584. +}
  585. +
  586. diff --git a/kget/conf/autopastemodel.h b/kget/conf/autopastemodel.h
  587. new file mode 100644
  588. index 0000000..b7fb18a
  589. --- /dev/null
  590. +++ b/kget/conf/autopastemodel.h
  591. @@ -0,0 +1,123 @@
  592. +/***************************************************************************
  593. +*   Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net>                     *
  594. +*                                                                         *
  595. +*   This program is free software; you can redistribute it and/or modify  *
  596. +*   it under the terms of the GNU General Public License as published by  *
  597. +*   the Free Software Foundation; either version 2 of the License, or     *
  598. +*   (at your option) any later version.                                   *
  599. +*                                                                         *
  600. +*   This program is distributed in the hope that it will be useful,       *
  601. +*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  602. +*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  603. +*   GNU General Public License for more details.                          *
  604. +*                                                                         *
  605. +*   You should have received a copy of the GNU General Public License     *
  606. +*   along with this program; if not, write to the                         *
  607. +*   Free Software Foundation, Inc.,                                       *
  608. +*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
  609. +***************************************************************************/
  610. +
  611. +#ifndef AUTOPASTEMODEL
  612. +#define AUTOPASTEMODEL
  613. +
  614. +#include <QtCore/QAbstractTableModel>
  615. +#include <QtGui/QStyledItemDelegate>
  616. +
  617. +class AutoPasteDelegate : public QStyledItemDelegate
  618. +{
  619. +    Q_OBJECT
  620. +
  621. +    public:
  622. +        AutoPasteDelegate(QAbstractItemModel *types, QAbstractItemModel *syntaxes, QObject *parent = 0);
  623. +
  624. +        QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
  625. +        void setEditorData(QWidget *editor, const QModelIndex &index) const;
  626. +        void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
  627. +        void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
  628. +        QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
  629. +
  630. +    private:
  631. +        QAbstractItemModel *m_types;
  632. +        QAbstractItemModel *m_syntaxes;
  633. +};
  634. +
  635. +class AutoPasteModel : public QAbstractTableModel
  636. +{
  637. +    Q_OBJECT
  638. +
  639. +    public:
  640. +        enum DataType {
  641. +            Type = 0,
  642. +            Pattern,
  643. +            PatternSyntax
  644. +        };
  645. +        enum TypeData {
  646. +            Include = 0,
  647. +            Exclude
  648. +        };
  649. +        enum PatternSyntaxData {
  650. +            Wildcard = 0,
  651. +            RegExp
  652. +        };
  653. +
  654. +        explicit AutoPasteModel(QObject *parent = 0);
  655. +        ~AutoPasteModel();
  656. +
  657. +        int rowCount(const QModelIndex &index = QModelIndex()) const;
  658. +        int columnCount(const QModelIndex &index = QModelIndex()) const;
  659. +        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
  660. +        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  661. +        Qt::ItemFlags flags(const QModelIndex &index) const;
  662. +        bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
  663. +        bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
  664. +
  665. +        /**
  666. +         * Adds an an item
  667. +         * @note do not use this for loading data
  668. +         * @see load()
  669. +         */
  670. +        void addItem(TypeData dataType, PatternSyntaxData patternSyntax, const QString &pattern);
  671. +
  672. +        /**
  673. +         * Moves an item to a new position
  674. +         * @param sourceRow the current row of the selected item
  675. +         * @param destinationRow is the new row before the move,
  676. +         * i.e. if sourceRow was not removed from the model
  677. +         * @see QAbstractItemModel::beginMoveRows()
  678. +         */
  679. +        bool moveItem(int sourceRow, int destinationRow);
  680. +
  681. +    public slots:
  682. +        /**
  683. +         * Loads the stored data
  684. +         * @see save()
  685. +         */
  686. +        void load();
  687. +
  688. +        /**
  689. +         * Saves the current data
  690. +         * @see load()
  691. +         */
  692. +        void save();
  693. +
  694. +        /**
  695. +         * Resets the model to the default data
  696. +         */
  697. +        void resetDefaults();
  698. +
  699. +    private:
  700. +        void addItems(const QList<int> &dataTypes, const QList<int> patternSyntaxes, const QStringList &patterns);
  701. +
  702. +    private:
  703. +        struct Data
  704. +        {
  705. +            TypeData type;
  706. +            QString pattern;
  707. +            PatternSyntaxData syntax;
  708. +        };
  709. +
  710. +        QList<Data> m_data;
  711. +};
  712. +
  713. +#endif
  714. +
  715. diff --git a/kget/conf/dlgadvanced.ui b/kget/conf/dlgadvanced.ui
  716. index a64df1f..2fe2572 100644
  717. --- a/kget/conf/dlgadvanced.ui
  718. +++ b/kget/conf/dlgadvanced.ui
  719. @@ -1,155 +1,300 @@
  720. -<ui version="4.0" >
  721. +<?xml version="1.0" encoding="UTF-8"?>
  722. +<ui version="4.0">
  723.   <class>DlgAdvanced</class>
  724. - <widget class="QWidget" name="DlgAdvanced" >
  725. -  <property name="geometry" >
  726. + <widget class="QWidget" name="DlgAdvanced">
  727. +  <property name="geometry">
  728.     <rect>
  729.      <x>0</x>
  730.      <y>0</y>
  731.      <width>585</width>
  732. -    <height>443</height>
  733. +    <height>494</height>
  734.     </rect>
  735.    </property>
  736. -  <layout class="QVBoxLayout" name="verticalLayout" >
  737. +  <layout class="QVBoxLayout" name="verticalLayout">
  738.     <item>
  739. -    <widget class="QCheckBox" name="kcfg_ExpertMode" >
  740. -     <property name="text" >
  741. +    <widget class="QCheckBox" name="kcfg_ExpertMode">
  742. +     <property name="text">
  743.        <string>Disable confirmation dialogs (less verbosity)</string>
  744.       </property>
  745.      </widget>
  746.     </item>
  747.     <item>
  748. -    <widget class="QCheckBox" name="kcfg_EnableSystemTray" >
  749. -     <property name="text" >
  750. +    <widget class="QCheckBox" name="kcfg_EnableSystemTray">
  751. +     <property name="text">
  752.        <string>Enable system tray icon</string>
  753.       </property>
  754.      </widget>
  755.     </item>
  756.     <item>
  757. -    <layout class="QFormLayout" name="formLayout_2" >
  758. -     <item row="0" column="0" >
  759. -      <widget class="QCheckBox" name="kcfg_AfterFinishActionEnabled" >
  760. -       <property name="text" >
  761. -        <string>Execute action after all downloads have been finished:</string>
  762. -       </property>
  763. -      </widget>
  764. -     </item>
  765. -     <item row="0" column="1" >
  766. -      <widget class="KComboBox" name="kcfg_AfterFinishAction" >
  767. +    <widget class="QTabWidget" name="tabWidget">
  768. +     <property name="currentIndex">
  769. +      <number>0</number>
  770. +     </property>
  771. +     <widget class="QWidget" name="tab">
  772. +      <attribute name="title">
  773. +       <string>Integration</string>
  774. +      </attribute>
  775. +      <layout class="QVBoxLayout" name="verticalLayout_2">
  776.         <item>
  777. -        <property name="text" >
  778. -         <string>Quit KGet</string>
  779. -        </property>
  780. +        <layout class="QFormLayout" name="formLayout">
  781. +         <item row="0" column="0">
  782. +          <widget class="QLabel" name="label_4">
  783. +           <property name="text">
  784. +            <string>Use as download manager for Konqueror:</string>
  785. +           </property>
  786. +          </widget>
  787. +         </item>
  788. +         <item row="0" column="1">
  789. +          <widget class="QCheckBox" name="kcfg_KonquerorIntegration">
  790. +           <property name="text">
  791. +            <string/>
  792. +           </property>
  793. +          </widget>
  794. +         </item>
  795. +         <item row="1" column="0">
  796. +          <widget class="QLabel" name="label_6">
  797. +           <property name="text">
  798. +            <string>Monitor clipboard for files to download:</string>
  799. +           </property>
  800. +          </widget>
  801. +         </item>
  802. +         <item row="1" column="1">
  803. +          <widget class="QCheckBox" name="kcfg_AutoPaste">
  804. +           <property name="text">
  805. +            <string/>
  806. +           </property>
  807. +          </widget>
  808. +         </item>
  809. +        </layout>
  810.         </item>
  811. -      </widget>
  812. -     </item>
  813. -     <item row="1" column="0" >
  814. -      <widget class="QLabel" name="label_2" >
  815. -       <property name="text" >
  816. -        <string>At startup:</string>
  817. -       </property>
  818. -      </widget>
  819. -     </item>
  820. -     <item row="1" column="1" >
  821. -      <widget class="KComboBox" name="kcfg_StartupAction" >
  822.         <item>
  823. -        <property name="text" >
  824. -         <string>Restore Download State</string>
  825. -        </property>
  826. +        <layout class="QHBoxLayout" name="horizontalLayout_4">
  827. +         <item>
  828. +          <spacer name="horizontalSpacer">
  829. +           <property name="orientation">
  830. +            <enum>Qt::Horizontal</enum>
  831. +           </property>
  832. +           <property name="sizeType">
  833. +            <enum>QSizePolicy::Fixed</enum>
  834. +           </property>
  835. +           <property name="sizeHint" stdset="0">
  836. +            <size>
  837. +             <width>40</width>
  838. +             <height>20</height>
  839. +            </size>
  840. +           </property>
  841. +          </spacer>
  842. +         </item>
  843. +         <item>
  844. +          <widget class="QWidget" name="autoPasteWidget" native="true">
  845. +           <layout class="QFormLayout" name="formLayout_6">
  846. +            <item row="0" column="0">
  847. +             <widget class="QLabel" name="label_5">
  848. +              <property name="text">
  849. +               <string>Case insensitive:</string>
  850. +              </property>
  851. +             </widget>
  852. +            </item>
  853. +            <item row="0" column="1">
  854. +             <widget class="QCheckBox" name="kcfg_AutoPasteCaseInsensitive">
  855. +              <property name="text">
  856. +               <string/>
  857. +              </property>
  858. +             </widget>
  859. +            </item>
  860. +            <item row="2" column="0" colspan="2">
  861. +             <layout class="QHBoxLayout" name="horizontalLayout_2">
  862. +              <item>
  863. +               <widget class="QTreeView" name="autoPasteList">
  864. +                <property name="selectionMode">
  865. +                 <enum>QAbstractItemView::ExtendedSelection</enum>
  866. +                </property>
  867. +                <property name="rootIsDecorated">
  868. +                 <bool>false</bool>
  869. +                </property>
  870. +                <property name="uniformRowHeights">
  871. +                 <bool>true</bool>
  872. +                </property>
  873. +               </widget>
  874. +              </item>
  875. +              <item>
  876. +               <layout class="QVBoxLayout" name="verticalLayout_4">
  877. +                <item>
  878. +                 <widget class="KPushButton" name="autoPasteAdd"/>
  879. +                </item>
  880. +                <item>
  881. +                 <widget class="KPushButton" name="autoPasteRemove"/>
  882. +                </item>
  883. +                <item>
  884. +                 <widget class="KPushButton" name="autoPasteIncrease">
  885. +                  <property name="text">
  886. +                   <string>Increase Priority</string>
  887. +                  </property>
  888. +                 </widget>
  889. +                </item>
  890. +                <item>
  891. +                 <widget class="KPushButton" name="autoPasteDecrease">
  892. +                  <property name="text">
  893. +                   <string>Decrease Priority</string>
  894. +                  </property>
  895. +                 </widget>
  896. +                </item>
  897. +                <item>
  898. +                 <spacer name="verticalSpacer">
  899. +                  <property name="orientation">
  900. +                   <enum>Qt::Vertical</enum>
  901. +                  </property>
  902. +                  <property name="sizeHint" stdset="0">
  903. +                   <size>
  904. +                    <width>20</width>
  905. +                    <height>40</height>
  906. +                   </size>
  907. +                  </property>
  908. +                 </spacer>
  909. +                </item>
  910. +               </layout>
  911. +              </item>
  912. +             </layout>
  913. +            </item>
  914. +            <item row="1" column="0" colspan="2">
  915. +             <layout class="QHBoxLayout" name="horizontalLayout">
  916. +              <item>
  917. +               <widget class="KComboBox" name="autoPasteType"/>
  918. +              </item>
  919. +              <item>
  920. +               <widget class="KComboBox" name="autoPastePatternSyntax"/>
  921. +              </item>
  922. +              <item>
  923. +               <widget class="KLineEdit" name="autoPastePattern">
  924. +                <property name="trapEnterKeyEvent" stdset="0">
  925. +                 <bool>true</bool>
  926. +                </property>
  927. +                <property name="showClearButton" stdset="0">
  928. +                 <bool>true</bool>
  929. +                </property>
  930. +               </widget>
  931. +              </item>
  932. +             </layout>
  933. +            </item>
  934. +           </layout>
  935. +          </widget>
  936. +         </item>
  937. +        </layout>
  938.         </item>
  939. -       <item>
  940. -        <property name="text" >
  941. -         <string>Start All Downloads</string>
  942. -        </property>
  943. +      </layout>
  944. +     </widget>
  945. +     <widget class="QWidget" name="tab_4">
  946. +      <attribute name="title">
  947. +       <string>Actions</string>
  948. +      </attribute>
  949. +      <layout class="QFormLayout" name="formLayout_5">
  950. +       <item row="1" column="0">
  951. +        <widget class="QLabel" name="label_2">
  952. +         <property name="text">
  953. +          <string>At startup:</string>
  954. +         </property>
  955. +        </widget>
  956.         </item>
  957. -       <item>
  958. -        <property name="text" >
  959. -         <string>Stop All Downloads</string>
  960. -        </property>
  961. +       <item row="1" column="1">
  962. +        <widget class="KComboBox" name="kcfg_StartupAction">
  963. +         <item>
  964. +          <property name="text">
  965. +           <string>Restore Download State</string>
  966. +          </property>
  967. +         </item>
  968. +         <item>
  969. +          <property name="text">
  970. +           <string>Start All Downloads</string>
  971. +          </property>
  972. +         </item>
  973. +         <item>
  974. +          <property name="text">
  975. +           <string>Stop All Downloads</string>
  976. +          </property>
  977. +         </item>
  978. +        </widget>
  979.         </item>
  980. -      </widget>
  981. -     </item>
  982. -    </layout>
  983. -   </item>
  984. -   <item>
  985. -    <widget class="QGroupBox" name="groupBox" >
  986. -     <property name="title" >
  987. -      <string>History</string>
  988. -     </property>
  989. -     <layout class="QFormLayout" name="formLayout" >
  990. -      <item row="0" column="0" >
  991. -       <widget class="QLabel" name="label" >
  992. -        <property name="text" >
  993. -         <string>History backend:</string>
  994. -        </property>
  995. -       </widget>
  996. -      </item>
  997. -      <item row="0" column="1" >
  998. -       <widget class="KComboBox" name="kcfg_HistoryBackend" />
  999. -      </item>
  1000. -     </layout>
  1001. -    </widget>
  1002. -   </item>
  1003. -   <item>
  1004. -    <widget class="QGroupBox" name="groupBox4" >
  1005. -     <property name="title" >
  1006. -      <string>Integration</string>
  1007. -     </property>
  1008. -     <layout class="QVBoxLayout" >
  1009. -      <item>
  1010. -       <widget class="QCheckBox" name="kcfg_KonquerorIntegration" >
  1011. -        <property name="text" >
  1012. -         <string>Use as download manager for Konqueror</string>
  1013. -        </property>
  1014. -       </widget>
  1015. -      </item>
  1016. -      <item>
  1017. -       <widget class="QCheckBox" name="kcfg_AutoPaste" >
  1018. -        <property name="text" >
  1019. -         <string>Monitor clipboard for files to download</string>
  1020. -        </property>
  1021. -       </widget>
  1022. -      </item>
  1023. -     </layout>
  1024. -    </widget>
  1025. -   </item>
  1026. -   <item>
  1027. -    <widget class="QGroupBox" name="kcfg_EnableKUIServerIntegration" >
  1028. -     <property name="title" >
  1029. -      <string>Enable KDE global progress tracking</string>
  1030. -     </property>
  1031. -     <property name="checkable" >
  1032. -      <bool>true</bool>
  1033. -     </property>
  1034. -     <property name="checked" >
  1035. -      <bool>false</bool>
  1036. -     </property>
  1037. -     <layout class="QVBoxLayout" >
  1038. -      <item>
  1039. -       <widget class="QRadioButton" name="kcfg_ExportSingleTransfer" >
  1040. -        <property name="text" >
  1041. -         <string>Show every single download </string>
  1042. -        </property>
  1043. -       </widget>
  1044. -      </item>
  1045. -      <item>
  1046. -       <widget class="QRadioButton" name="kcfg_ExportGlobalJob" >
  1047. -        <property name="text" >
  1048. -         <string>Show overall progress</string>
  1049. -        </property>
  1050. -       </widget>
  1051. -      </item>
  1052. -     </layout>
  1053. +       <item row="0" column="0">
  1054. +        <widget class="QCheckBox" name="kcfg_AfterFinishActionEnabled">
  1055. +         <property name="text">
  1056. +          <string>Execute action after all downloads have been finished:</string>
  1057. +         </property>
  1058. +        </widget>
  1059. +       </item>
  1060. +       <item row="0" column="1">
  1061. +        <widget class="KComboBox" name="kcfg_AfterFinishAction">
  1062. +         <item>
  1063. +          <property name="text">
  1064. +           <string>Quit KGet</string>
  1065. +          </property>
  1066. +         </item>
  1067. +        </widget>
  1068. +       </item>
  1069. +      </layout>
  1070. +     </widget>
  1071. +     <widget class="QWidget" name="tab_2">
  1072. +      <attribute name="title">
  1073. +       <string>History</string>
  1074. +      </attribute>
  1075. +      <layout class="QFormLayout" name="formLayout_3">
  1076. +       <item row="0" column="0">
  1077. +        <widget class="QLabel" name="label">
  1078. +         <property name="text">
  1079. +          <string>History backend:</string>
  1080. +         </property>
  1081. +        </widget>
  1082. +       </item>
  1083. +       <item row="0" column="1">
  1084. +        <widget class="KComboBox" name="kcfg_HistoryBackend"/>
  1085. +       </item>
  1086. +      </layout>
  1087. +     </widget>
  1088. +     <widget class="QWidget" name="tab_3">
  1089. +      <attribute name="title">
  1090. +       <string>Progress tracking</string>
  1091. +      </attribute>
  1092. +      <layout class="QFormLayout" name="formLayout_4">
  1093. +       <item row="0" column="1">
  1094. +        <widget class="QCheckBox" name="kcfg_EnableKUIServerIntegration">
  1095. +         <property name="text">
  1096. +          <string/>
  1097. +         </property>
  1098. +        </widget>
  1099. +       </item>
  1100. +       <item row="0" column="0">
  1101. +        <widget class="QLabel" name="label_3">
  1102. +         <property name="text">
  1103. +          <string>Enable KDE global progress tracking:</string>
  1104. +         </property>
  1105. +        </widget>
  1106. +       </item>
  1107. +       <item row="1" column="1">
  1108. +        <widget class="QRadioButton" name="kcfg_ExportSingleTransfer">
  1109. +         <property name="text">
  1110. +          <string>Show every single download </string>
  1111. +         </property>
  1112. +        </widget>
  1113. +       </item>
  1114. +       <item row="2" column="1">
  1115. +        <widget class="QRadioButton" name="kcfg_ExportGlobalJob">
  1116. +         <property name="text">
  1117. +          <string>Show overall progress</string>
  1118. +         </property>
  1119. +        </widget>
  1120. +       </item>
  1121. +      </layout>
  1122. +     </widget>
  1123.      </widget>
  1124.     </item>
  1125.     <item>
  1126.      <spacer>
  1127. -     <property name="orientation" >
  1128. +     <property name="orientation">
  1129.        <enum>Qt::Vertical</enum>
  1130.       </property>
  1131. -     <property name="sizeType" >
  1132. +     <property name="sizeType">
  1133.        <enum>QSizePolicy::Expanding</enum>
  1134.       </property>
  1135. -     <property name="sizeHint" stdset="0" >
  1136. +     <property name="sizeHint" stdset="0">
  1137.        <size>
  1138.         <width>200</width>
  1139.         <height>20</height>
  1140. @@ -159,7 +304,17 @@
  1141.     </item>
  1142.    </layout>
  1143.   </widget>
  1144. -  <customwidgets>
  1145. + <customwidgets>
  1146. +  <customwidget>
  1147. +   <class>KPushButton</class>
  1148. +   <extends>QPushButton</extends>
  1149. +   <header>kpushbutton.h</header>
  1150. +  </customwidget>
  1151. +  <customwidget>
  1152. +   <class>KLineEdit</class>
  1153. +   <extends>QLineEdit</extends>
  1154. +   <header>klineedit.h</header>
  1155. +  </customwidget>
  1156.    <customwidget>
  1157.     <class>KComboBox</class>
  1158.     <extends>QComboBox</extends>
  1159. @@ -167,5 +322,70 @@
  1160.    </customwidget>
  1161.   </customwidgets>
  1162.   <resources/>
  1163. - <connections/>
  1164. + <connections>
  1165. +  <connection>
  1166. +   <sender>kcfg_AfterFinishActionEnabled</sender>
  1167. +   <signal>toggled(bool)</signal>
  1168. +   <receiver>kcfg_AfterFinishAction</receiver>
  1169. +   <slot>setEnabled(bool)</slot>
  1170. +   <hints>
  1171. +    <hint type="sourcelabel">
  1172. +     <x>170</x>
  1173. +     <y>70</y>
  1174. +    </hint>
  1175. +    <hint type="destinationlabel">
  1176. +     <x>379</x>
  1177. +     <y>70</y>
  1178. +    </hint>
  1179. +   </hints>
  1180. +  </connection>
  1181. +  <connection>
  1182. +   <sender>kcfg_EnableKUIServerIntegration</sender>
  1183. +   <signal>toggled(bool)</signal>
  1184. +   <receiver>kcfg_ExportSingleTransfer</receiver>
  1185. +   <slot>setEnabled(bool)</slot>
  1186. +   <hints>
  1187. +    <hint type="sourcelabel">
  1188. +     <x>29</x>
  1189. +     <y>147</y>
  1190. +    </hint>
  1191. +    <hint type="destinationlabel">
  1192. +     <x>316</x>
  1193. +     <y>182</y>
  1194. +    </hint>
  1195. +   </hints>
  1196. +  </connection>
  1197. +  <connection>
  1198. +   <sender>kcfg_EnableKUIServerIntegration</sender>
  1199. +   <signal>toggled(bool)</signal>
  1200. +   <receiver>kcfg_ExportGlobalJob</receiver>
  1201. +   <slot>setEnabled(bool)</slot>
  1202. +   <hints>
  1203. +    <hint type="sourcelabel">
  1204. +     <x>236</x>
  1205. +     <y>156</y>
  1206. +    </hint>
  1207. +    <hint type="destinationlabel">
  1208. +     <x>298</x>
  1209. +     <y>207</y>
  1210. +    </hint>
  1211. +   </hints>
  1212. +  </connection>
  1213. +  <connection>
  1214. +   <sender>kcfg_AutoPaste</sender>
  1215. +   <signal>toggled(bool)</signal>
  1216. +   <receiver>autoPasteWidget</receiver>
  1217. +   <slot>setEnabled(bool)</slot>
  1218. +   <hints>
  1219. +    <hint type="sourcelabel">
  1220. +     <x>264</x>
  1221. +     <y>126</y>
  1222. +    </hint>
  1223. +    <hint type="destinationlabel">
  1224. +     <x>314</x>
  1225. +     <y>274</y>
  1226. +    </hint>
  1227. +   </hints>
  1228. +  </connection>
  1229. + </connections>
  1230.  </ui>
  1231. diff --git a/kget/conf/kget.kcfg b/kget/conf/kget.kcfg
  1232. index 220fa1a..997e1c6 100644
  1233. --- a/kget/conf/kget.kcfg
  1234. +++ b/kget/conf/kget.kcfg
  1235. @@ -15,6 +15,8 @@
  1236.      </entry>
  1237.      <entry name="VerificationHeaderState" type="String">
  1238.      </entry>
  1239. +    <entry name="AutoPasteHeaderState" type="String">
  1240. +    </entry>
  1241.      <entry name="ShowMain" type="Bool">
  1242.        <default>true</default>
  1243.      </entry>
  1244. @@ -49,6 +51,18 @@
  1245.      <entry name="AutoPaste" type="Bool">
  1246.        <default>false</default>
  1247.      </entry>
  1248. +    <entry name="AutoPasteCaseInsensitive" type="Bool">
  1249. +        <default>true</default>
  1250. +    </entry>
  1251. +    <entry name="AutoPastePatterns" type="StringList">
  1252. +        <default>*</default>
  1253. +    </entry>
  1254. +    <entry name="AutoPasteTypes" type="IntList">
  1255. +        <default>0</default>
  1256. +    </entry>
  1257. +    <entry name="AutoPastePatternSyntaxes" type="IntList">
  1258. +        <default>0</default>
  1259. +    </entry>
  1260.      <entry name="TimedDownload" type="Bool">
  1261.        <default>false</default>
  1262.      </entry>
  1263. diff --git a/kget/conf/preferencesdialog.cpp b/kget/conf/preferencesdialog.cpp
  1264. index 8973813..8d94802 100644
  1265. --- a/kget/conf/preferencesdialog.cpp
  1266. +++ b/kget/conf/preferencesdialog.cpp
  1267. @@ -8,13 +8,12 @@
  1268.  */
  1269.  
  1270.  #include "preferencesdialog.h"
  1271. -#include "core/kget.h"
  1272. -#include "core/transferhistorystore.h"
  1273.  
  1274.  #include "ui_dlgappearance.h"
  1275.  #include "ui_dlgnetwork.h"
  1276.  #include "dlgwebinterface.h"
  1277.  
  1278. +#include "advancedpreferences.h"
  1279.  #include "transfersgroupwidget.h"
  1280.  #include "pluginselector.h"
  1281.  #include "verificationpreferences.h"
  1282. @@ -29,7 +28,8 @@ PreferencesDialog::PreferencesDialog(QWidget * parent, KConfigSkeleton * skeleto
  1283.      TransfersGroupWidget *groups = new TransfersGroupWidget(this);
  1284.      DlgWebinterface *webinterface = new DlgWebinterface(this);
  1285.      QWidget *network = new QWidget(this);
  1286. -    QWidget *advanced = new QWidget(this);
  1287. +    AdvancedPreferences *advanced = new AdvancedPreferences(this);
  1288. +    connect(advanced, SIGNAL(changed()), SLOT(enableApplyButton()));
  1289.      VerificationPreferences *verification = new VerificationPreferences(this);
  1290.      connect(verification, SIGNAL(changed()), SLOT(enableApplyButton()));
  1291.      PluginSelector * pluginSelector = new PluginSelector(this);
  1292. @@ -40,27 +40,6 @@ PreferencesDialog::PreferencesDialog(QWidget * parent, KConfigSkeleton * skeleto
  1293.  
  1294.      dlgApp.setupUi(appearance);
  1295.      dlgNet.setupUi(network);
  1296. -    dlgAdv.setupUi(advanced);
  1297. -
  1298. -    // history backend entries
  1299. -    dlgAdv.kcfg_HistoryBackend->addItem(i18n("Xml"), QVariant(TransferHistoryStore::Xml));
  1300. -#ifdef HAVE_SQLITE
  1301. -    dlgAdv.kcfg_HistoryBackend->addItem(i18n("Sqlite"), QVariant(TransferHistoryStore::SQLite));
  1302. -#endif
  1303. -#ifdef HAVE_NEPOMUK
  1304. -    dlgAdv.kcfg_HistoryBackend->addItem(i18n("Nepomuk"), QVariant(TransferHistoryStore::Nepomuk));
  1305. -#endif
  1306. -
  1307. -#ifdef HAVE_KWORKSPACE
  1308. -    dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Turn Off Computer"), QVariant(KGet::Shutdown));
  1309. -    dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Hibernate Computer"), QVariant(KGet::Hibernate));
  1310. -    dlgAdv.kcfg_AfterFinishAction->addItem(i18n("Suspend Computer"), QVariant(KGet::Suspend));
  1311. -#endif
  1312. -
  1313. -    // enable or disable the AfterFinishAction depends on the AfterFinishActionEnabled checkbox state
  1314. -    dlgAdv.kcfg_AfterFinishAction->setEnabled(dlgAdv.kcfg_AfterFinishActionEnabled->checkState () == Qt::Checked);
  1315. -    connect(dlgAdv.kcfg_AfterFinishActionEnabled, SIGNAL(stateChanged(int)),
  1316. -                                                  SLOT(slotToggleAfterFinishAction(int)));
  1317.  
  1318.      // TODO: remove the following lines as soon as these features are ready
  1319.      dlgNet.lb_per_transfer->setVisible(false);
  1320. @@ -91,7 +70,3 @@ void PreferencesDialog::enableApplyButton()
  1321.      enableButtonApply(true);
  1322.  }
  1323.  
  1324. -void PreferencesDialog::slotToggleAfterFinishAction(int state)
  1325. -{
  1326. -    dlgAdv.kcfg_AfterFinishAction->setEnabled(state == Qt::Checked);
  1327. -}
  1328. diff --git a/kget/conf/preferencesdialog.h b/kget/conf/preferencesdialog.h
  1329. index aaa3054..8acc3fb 100644
  1330. --- a/kget/conf/preferencesdialog.h
  1331. +++ b/kget/conf/preferencesdialog.h
  1332. @@ -10,14 +10,8 @@
  1333.  #ifndef PREFERENCESDIALOG_H
  1334.  #define PREFERENCESDIALOG_H
  1335.  
  1336. -#include "ui_dlgadvanced.h"
  1337. -
  1338.  #include <kconfigdialog.h>
  1339.  
  1340. -class QWidget;
  1341. -class KConfigSkeleton;
  1342. -class KTabWidget;
  1343. -
  1344.  class PreferencesDialog : public KConfigDialog
  1345.  {
  1346.      Q_OBJECT
  1347. @@ -25,12 +19,8 @@ class PreferencesDialog : public KConfigDialog
  1348.          PreferencesDialog( QWidget * parent, KConfigSkeleton * config );
  1349.  
  1350.      private slots:
  1351. -        void slotToggleAfterFinishAction(int state);
  1352.          void disableApplyButton();
  1353.          void enableApplyButton();
  1354. -
  1355. -    private:
  1356. -        Ui::DlgAdvanced dlgAdv;
  1357.  };
  1358.  
  1359.  #endif
  1360. diff --git a/kget/mainwindow.cpp b/kget/mainwindow.cpp
  1361. index aa93f75..24f10db 100644
  1362. --- a/kget/mainwindow.cpp
  1363. +++ b/kget/mainwindow.cpp
  1364. @@ -22,6 +22,7 @@
  1365.  #include "core/transfertreemodel.h"
  1366.  #include "core/transfertreeselectionmodel.h"
  1367.  #include "settings.h"
  1368. +#include "conf/autopastemodel.h"
  1369.  #include "conf/preferencesdialog.h"
  1370.  #include "ui/viewscontainer.h"
  1371.  #include "ui/tray.h"
  1372. @@ -967,7 +968,26 @@ void MainWindow::slotCheckClipboard()
  1373.  
  1374.          const KUrl url = KUrl(lastClipboard);
  1375.          if (url.isValid() && !url.protocol().isEmpty() && url.hasPath() && url.hasHost() && !url.isLocalFile()) {
  1376. -            KGet::addTransfer( url );
  1377. +            bool add = false;
  1378. +            const QString urlString = url.url();
  1379. +
  1380. +            //check the combined whitelist and blacklist
  1381. +            const QList<int> types = Settings::autoPasteTypes();
  1382. +            const QList<int> syntaxes = Settings::autoPastePatternSyntaxes();
  1383. +            const QStringList patterns = Settings::autoPastePatterns();
  1384. +            const Qt::CaseSensitivity cs = (Settings::autoPasteCaseInsensitive() ? Qt::CaseInsensitive : Qt::CaseSensitive);
  1385. +            for (int i = 0; i < types.count(); ++i) {
  1386. +                const QRegExp::PatternSyntax syntax = (syntaxes[i] == AutoPasteModel::Wildcard ? QRegExp::Wildcard : QRegExp::RegExp2);
  1387. +                QRegExp rx(patterns[i], cs, syntax);//TODO case insensitivity + type
  1388. +                if (rx.exactMatch(urlString)) {
  1389. +                    add = (types[i] == AutoPasteModel::Include);
  1390. +                    break;
  1391. +                }
  1392. +            }
  1393. +
  1394. +            if (add) {
  1395. +                KGet::addTransfer(url);
  1396. +            }
  1397.          }
  1398.      }
  1399.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement