All pastes #1893361 Raw Edit

Miscellany

public cpp v1 · immutable
#1893361 ·published 2010-07-02 11:29 UTC
rendered paste body
diff --git a/kget/core/transfertreemodel.cpp b/kget/core/transfertreemodel.cppindex 196547d..50b9599 100644--- a/kget/core/transfertreemodel.cpp+++ b/kget/core/transfertreemodel.cpp@@ -2,6 +2,7 @@     Copyright (C) 2006 Dario Massarin <nekkar@libero.it>    Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>+   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@@ -326,6 +327,15 @@ void TransferTreeModel::moveTransfer(Transfer * transfer, TransferGroup * destGr     KGet::selectionModel()->clearSelection(); } +void TransferTreeModel::moveTransfer(TransferHandler *transfer, TransferGroupHandler *destGroup, TransferHandler *after)+{+    Transfer *afterTransfer = 0;+    if (after) {+        afterTransfer = after->m_transfer;+    }+    moveTransfer(transfer->m_transfer, destGroup->m_group, afterTransfer);+}+ QList<TransferGroup *> TransferTreeModel::transferGroups() {     QList<TransferGroup*> transferGroups;diff --git a/kget/core/transfertreemodel.h b/kget/core/transfertreemodel.hindex 289df3b..8f1e8c0 100644--- a/kget/core/transfertreemodel.h+++ b/kget/core/transfertreemodel.h@@ -2,6 +2,7 @@     Copyright (C) 2006 Dario Massarin <nekkar@libero.it>    Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>+   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@@ -112,6 +113,7 @@ class KGET_EXPORT TransferTreeModel : public QStandardItemModel         ModelItem * itemFromIndex(const QModelIndex &index) const;          void moveTransfer(Transfer * transfer, TransferGroup * destGroup, Transfer * after = 0);+        void moveTransfer(TransferHandler *transfer, TransferGroupHandler *destGroup, TransferHandler *after = 0);          QList<TransferGroup *> transferGroups(); diff --git a/kget/mainwindow.cpp b/kget/mainwindow.cppindex 3ec9cad..8faa6e3 100644--- a/kget/mainwindow.cpp+++ b/kget/mainwindow.cpp@@ -6,6 +6,7 @@    Copyright (C) 2006 - 2008 Urs Wolfer <uwolfer @ kde.org>    Copyright (C) 2006 Dario Massarin <nekkar@libero.it>    Copyright (C) 2008 - 2009 Lukas Appelhans <l.appelhans@gmx.de>+   Copyright (C) 2009 - 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@@ -186,6 +187,26 @@ void MainWindow::setupActions()     createMetalinkAction->setText(i18n("&Create a Metalink"));     connect(createMetalinkAction, SIGNAL(triggered()), SLOT(slotCreateMetalink())); +    KAction *priorityTop = actionCollection()->addAction("priority_top");+    priorityTop->setText(i18n("Top Priority"));+    priorityTop->setIcon(KIcon("arrow-up-double"));+    connect(priorityTop, SIGNAL(triggered()), this, SLOT(slotPriorityTop()));++    KAction *priorityBottom = actionCollection()->addAction("priority_bottom");+    priorityBottom->setText(i18n("Least Priority"));+    priorityBottom->setIcon(KIcon("arrow-down-double"));+    connect(priorityBottom, SIGNAL(triggered()), this, SLOT(slotPriorityBottom()));++    KAction *priorityUp = actionCollection()->addAction("priority_up");+    priorityUp->setText(i18n("Increase Priority"));+    priorityUp->setIcon(KIcon("arrow-up"));+    connect(priorityUp, SIGNAL(triggered()), this, SLOT(slotPriorityUp()));++    KAction *priorityDown = actionCollection()->addAction("priority_down");+    priorityDown->setText(i18n("Decrease Priority"));+    priorityDown->setIcon(KIcon("arrow-down"));+    connect(priorityDown, SIGNAL(triggered()), this, SLOT(slotPriorityDown()));+     KAction *deleteGroupAction = actionCollection()->addAction("delete_groups");     deleteGroupAction->setText(i18n("Delete Group"));     deleteGroupAction->setIcon(KIcon("edit-delete"));@@ -659,6 +680,141 @@ void MainWindow::slotRedownloadSelected()     } } +void MainWindow::slotPriorityTop()+{+    QList<TransferHandler*> selected = KGet::selectedTransfers();+    TransferHandler *after = 0;+    TransferGroupHandler *group = 0;+    foreach (TransferHandler *transfer, selected) {+        if (!transfer) {+            continue;+        }++        //previous transfer was not of the same group, so after has to be reset as the group+        if (!group || (group != transfer->group())) {+            after = 0;+            group = transfer->group();+        }+        KGet::model()->moveTransfer(transfer, group, after);+        after = transfer;+    }+}++void MainWindow::slotPriorityBottom()+{+    QList<TransferHandler*> selected = KGet::selectedTransfers();+    QList<TransferHandler*> groupTransfers;+    TransferHandler *after = 0;+    TransferGroupHandler *group = 0;+    foreach (TransferHandler *transfer, selected) {+        if (!transfer) {+            continue;+        }++        //previous transfer was not of the same group, so after has to be reset as the group+        if (!group || (group != transfer->group())) {+            group = transfer->group();+            groupTransfers = group->transfers();+            if (groupTransfers.isEmpty()) {+                after = 0;+            } else {+                after = groupTransfers.last();+            }+        }++        KGet::model()->moveTransfer(transfer, group, after);+        after = transfer;+    }+}++void MainWindow::slotPriorityUp()+{+    QList<TransferHandler*> selected = KGet::selectedTransfers();+    QList<TransferHandler*> groupTransfers;+    TransferHandler *after = 0;+    int newIndex = -1;+    TransferGroupHandler *group = 0;+    foreach (TransferHandler *transfer, selected) {+        if (!transfer) {+            continue;+        }++        //previous transfer was not of the same group, so group has to be reset+        if (!group || (group != transfer->group())) {+            group = transfer->group();+            groupTransfers = group->transfers();+        }++        after = 0;+        if (!groupTransfers.isEmpty()) {+            int index = groupTransfers.indexOf(transfer);++            //do not move higher than the first place+            if (index > 0) {+                //if only Transfers at the top are select do not change their order+                if ((index - 1) != newIndex) {+                    newIndex = index - 1;+                    if (newIndex - 1 >= 0) {+                        after = groupTransfers[newIndex - 1];+                    }++                    //keep the list with the actual movements synchronised+                    groupTransfers.move(index, newIndex);++                    KGet::model()->moveTransfer(transfer, group, after);+                } else {+                    newIndex = index;+                }+            } else {+                newIndex = 0;+            }+        }+    }+}++void MainWindow::slotPriorityDown()+{+    QList<TransferHandler*> selected = KGet::selectedTransfers();+    QList<TransferHandler*> groupTransfers;+    int newIndex = -1;+    TransferGroupHandler *group = 0;+    for (int i = selected.count() - 1; i >= 0; --i) {+        TransferHandler *transfer = selected[i];+        if (!transfer) {+            continue;+        }++        //previous transfer was not of the same group, so group has to be reset+        if (!group || (group != transfer->group())) {+            group = transfer->group();+            groupTransfers = group->transfers();+        }++        if (!groupTransfers.isEmpty()) {+            int index = groupTransfers.indexOf(transfer);++            //do not move lower than the last place+            if ((index != -1) && (index + 1 < groupTransfers.count())) {+                //if only Transfers at the top are select do not change their order+                if ((index + 1) != newIndex) {+                    newIndex = index + 1;+                    TransferHandler *after = groupTransfers[newIndex];+++                    //keep the list with the actual movements synchronised+                    groupTransfers.move(index, newIndex);++                    KGet::model()->moveTransfer(transfer, group, after);+                } else {+                    newIndex = index;+                }+            } else {+                newIndex = index;+            }+        }+    }+}+ void MainWindow::slotTransfersOpenDest() {     QStringList openedDirs;diff --git a/kget/mainwindow.h b/kget/mainwindow.hindex d2cab02..b0801cc 100644--- a/kget/mainwindow.h+++ b/kget/mainwindow.h@@ -3,6 +3,7 @@    Copyright (C) 2002 by Patrick Charbonnier <pch@freeshell.org>    Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss    Copyright (C) 2006 Dario Massarin <nekkar@libero.it>+   Copyright (C) 2009 - 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@@ -89,6 +90,10 @@ private slots:     void slotTransferGroupSettings();     void slotTransferSettings();     void slotCreateMetalink();+    void slotPriorityTop();+    void slotPriorityBottom();+    void slotPriorityUp();+    void slotPriorityDown();      // transfers slots     void slotStopAllDownload();diff --git a/kget/ui/kgetui.rc b/kget/ui/kgetui.rcindex 43fdd42..08d7945 100644--- a/kget/ui/kgetui.rc+++ b/kget/ui/kgetui.rc@@ -1,5 +1,5 @@ <!DOCTYPE kpartgui>-<kpartgui name="kget" version="7">+<kpartgui name="kget" version="8"> <MenuBar>     <Menu noMerge="1" name="file"><text>&amp;File</text>         <Action name="new_download"/>@@ -20,7 +20,12 @@         <Separator/>                 <Action name="stop_all_download"/>         <Action name="stop_selected_download"/>-        <Separator/>        +        <Separator/>+        <Action name="priority_top"/>+        <Action name="priority_up"/>+        <Action name="priority_down"/>+        <Action name="priority_bottom"/>+        <Separator/>         <Action name="delete_selected_download"/>         <Action name="delete_all_finished"/>         <Separator/>