Bug 134235 - add "move to top" and "move to bottom" queue menu entries
Summary: add "move to top" and "move to bottom" queue menu entries
Status: RESOLVED FIXED
Alias: None
Product: kftpgrabber
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Debian testing Linux
: NOR wishlist
Target Milestone: ---
Assignee: Jernej Kos
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-17 22:59 UTC by Gabriele Armao
Modified: 2006-09-28 20:16 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriele Armao 2006-09-17 22:59:13 UTC
Version:            (using KDE KDE 3.5.4)
Installed from:    Debian testing/unstable Packages

add "move to top" and "move to bottom" queue menu entries
Comment 1 Jernej Kos 2006-09-28 20:16:12 UTC
SVN commit 589828 by kostko:

Added support for moving transfers to top/bottom and some minor cleanups.

FEATURE: 134235

 M  +24 -18    kftpqueue.cpp  
 M  +24 -16    kftpqueue.h  
 M  +14 -2     queueobject.cpp  
 M  +15 -1     queueobject.h  
 M  +33 -27    widgets/queueview/queueview.cpp  
 M  +4 -0      widgets/queueview/queueview.h  


--- trunk/extragear/network/kftpgrabber/src/kftpqueue.cpp #589827:589828
@@ -370,12 +370,6 @@
     emit queueUpdate();
 }
 
-void Manager::removeTransfer(long id)
-{
-  // Just remove the transfer we find via id
-  removeTransfer(findTransfer(id));
-}
-
 void Manager::revalidateTransfer(Transfer *transfer)
 {
   QueueObject *i = transfer;
@@ -436,36 +430,48 @@
   }
 }
 
-void Manager::moveTransferUp(long id)
+void Manager::moveTransferUp(QueueObject *object)
 {
-  Transfer *transfer = findTransfer(id);
-  transfer->parentObject()->moveChildUp(transfer);
+  object->parentObject()->moveChildUp(object);
 
   if (m_emitUpdate)
     emit queueUpdate();
 }
 
-void Manager::moveTransferDown(long id)
+void Manager::moveTransferDown(QueueObject *object)
 {
-  Transfer *transfer = findTransfer(id);
-  transfer->parentObject()->moveChildDown(transfer);
+  object->parentObject()->moveChildDown(object);
 
   if (m_emitUpdate)
     emit queueUpdate();
 }
 
-bool Manager::canBeMovedUp(long id)
+void Manager::moveTransferTop(QueueObject *object)
 {
-  Transfer *transfer = findTransfer(id);
-  return transfer ? transfer->parentObject()->canMoveChildUp(transfer) : false;
+  object->parentObject()->moveChildTop(object);
+
+  if (m_emitUpdate)
+    emit queueUpdate();
 }
 
-bool Manager::canBeMovedDown(long id)
+void Manager::moveTransferBottom(QueueObject *object)
 {
-  Transfer *transfer = findTransfer(id);
-  return transfer ? transfer->parentObject()->canMoveChildDown(transfer) : false;
+  object->parentObject()->moveChildBottom(object);
+
+  if (m_emitUpdate)
+    emit queueUpdate();
 }
 
+bool Manager::canBeMovedUp(QueueObject *object)
+{
+  return object ? object->parentObject()->canMoveChildUp(object) : false;
+}
+
+bool Manager::canBeMovedDown(QueueObject *object)
+{
+  return object ? object->parentObject()->canMoveChildDown(object) : false;
+}
+
 void Manager::doEmitUpdate()
 {
   m_curDownSpeed = 0;
--- trunk/extragear/network/kftpgrabber/src/kftpqueue.h #589827:589828
@@ -170,14 +170,6 @@
     void removeTransfer(Transfer *transfer, bool abortSession = true);
     
     /**
-     * Removes a transfer from the queue. This method just finds the object first by doing
-     * a findTransfer.
-     *
-     * @param id The transfer's id
-     */
-    void removeTransfer(long id);
-    
-    /**
      * This method removes all the transfers from the queue.
      */
     void clearQueue();
@@ -223,32 +215,48 @@
     /**
      * Moves the specified transfer up in the queue.
      *
-     * @param id Id of the transfer to be moved
+     * @param object The queue object to be moved
      */
-    void moveTransferUp(long id);
+    void moveTransferUp(QueueObject *object);
     
     /**
      * Moves the specified transfer down in the queue.
      *
-     * @param id Id of the transfer to be moved
+     * @param object The queue object to be moved
      */
-    void moveTransferDown(long id);
+    void moveTransferDown(QueueObject *object);
     
     /**
+     * Moves the specified transfer to the top of the queue (only within the
+     * parent boundaries).
+     *
+     * @param object The queue object to be moved
+     */
+    void moveTransferTop(QueueObject *object);
+    
+    /**
+     * Moves the specified transfer to the bottom of the queue (only within the
+     * parent boundaries).
+     *
+     * @param object The queue object to be moved
+     */
+    void moveTransferBottom(QueueObject *object);
+    
+    /**
      * Can the transfer be moved up ?
      *
-     * @param id Id of the transfer to be moved
+     * @param object The queue object to be moved
      * @return True if the transfer can be moved
      */
-    bool canBeMovedUp(long id);
+    bool canBeMovedUp(QueueObject *object);
     
     /**
      * Can the transfer be moved down ?
      *
-     * @param id Id of the transfer to be moved
+     * @param object The queue object to be moved
      * @return True if the transfer can be moved
      */
-    bool canBeMovedDown(long id);
+    bool canBeMovedDown(QueueObject *object);
     
     /**
      * Returns the list of failed transfers.
--- trunk/extragear/network/kftpgrabber/src/queueobject.cpp #589827:589828
@@ -191,7 +191,7 @@
   if (m_children.findRef(child) != -1) {
     if (m_children.prev()) {
       int prevPos = m_children.at();
-      m_children.remove(child);
+      m_children.removeRef(child);
       m_children.insert(prevPos, child);
     }
   }
@@ -202,12 +202,24 @@
   if (m_children.findRef(child) != -1) {
     if (m_children.next()) {
       int nextPos = m_children.at();
-      m_children.remove(child);
+      m_children.removeRef(child);
       m_children.insert(nextPos, child);
     }
   }
 }
 
+void QueueObject::moveChildTop(QueueObject *child)
+{
+  m_children.removeRef(child);
+  m_children.prepend(child);
+}
+
+void QueueObject::moveChildBottom(QueueObject *child)
+{
+  m_children.removeRef(child);
+  m_children.append(child);
+}
+
 bool QueueObject::canMoveChildUp(QueueObject *child)
 {
   if (!child->canMove()) return false;
--- trunk/extragear/network/kftpgrabber/src/queueobject.h #589827:589828
@@ -228,7 +228,7 @@
     /**
      * Set transfer's ID.
      *
-     * @param Transfer's ID -- it *MUST* be unique.
+     * @param id Transfer identifier (must be unique)
      */
     void setId(long id) { m_id = id; }
     
@@ -287,6 +287,20 @@
     void moveChildDown(QueueObject *child);
     
     /**
+     * Move a child object to the top.
+     *
+     * @param child The object to move
+     */
+    void moveChildTop(QueueObject *child);
+    
+    /**
+     * Move a child object to the bottom.
+     *
+     * @param child The object to move
+     */
+    void moveChildBottom(QueueObject *child);
+    
+    /**
      * Can a child be moved up ?
      *
      * @param child The child to be moved
--- trunk/extragear/network/kftpgrabber/src/widgets/queueview/queueview.cpp #589827:589828
@@ -409,6 +409,8 @@
   m_removeAllAction = new KAction(i18n("Remove &All"), KShortcut(), this, SLOT(slotRemoveAll()), actionCollection(), "removeAll");
   m_moveUpAction = new KAction(i18n("Move &Up"), "up", KShortcut(), this, SLOT(slotMoveUp()), actionCollection(), "moveUp");
   m_moveDownAction = new KAction(i18n("Move &Down"), "down", KShortcut("del"), this, SLOT(slotMoveDown()), actionCollection(), "moveDown");
+  m_moveTopAction = new KAction(i18n("Move To &Top"), "top", KShortcut(), this, SLOT(slotMoveTop()), actionCollection(), "moveTop");
+  m_moveBottomAction = new KAction(i18n("Move To &Bottom"), "bottom", KShortcut(), this, SLOT(slotMoveBottom()), actionCollection(), "moveBottom");
   m_editAction = new KAction(i18n("&Change Transfer Info"), KShortcut(), this, SLOT(slotEdit()), actionCollection(), "changeTransfer");
 
   // Create the toolbar actions
@@ -465,8 +467,11 @@
     }
   }
   
-  m_moveUpAction->setEnabled(allowMove && KFTPQueue::Manager::self()->canBeMovedUp(firstItem->getObject()->getId()) && !locked);
-  m_moveDownAction->setEnabled(allowMove && KFTPQueue::Manager::self()->canBeMovedDown(static_cast<QueueViewItem*>(selection.last())->getObject()->getId()) && !locked);
+  m_moveUpAction->setEnabled(allowMove && KFTPQueue::Manager::self()->canBeMovedUp(firstItem->getObject()) && !locked);
+  m_moveDownAction->setEnabled(allowMove && KFTPQueue::Manager::self()->canBeMovedDown(static_cast<QueueViewItem*>(selection.last())->getObject()) && !locked);
+  
+  m_moveTopAction->setEnabled(allowMove && KFTPQueue::Manager::self()->canBeMovedUp(firstItem->getObject()) && !locked);
+  m_moveBottomAction->setEnabled(allowMove && KFTPQueue::Manager::self()->canBeMovedDown(static_cast<QueueViewItem*>(selection.last())->getObject()) && !locked);
 }
 
 void QueueView::slotSiteAdded(KFTPQueue::Site *site)
@@ -529,8 +534,10 @@
     m_removeAction->plug(contextMenu);
     m_removeAllAction->plug(contextMenu);
     contextMenu->insertSeparator();
+    m_moveTopAction->plug(contextMenu);
     m_moveUpAction->plug(contextMenu);
     m_moveDownAction->plug(contextMenu);
+    m_moveBottomAction->plug(contextMenu);
     contextMenu->insertSeparator();
     m_editAction->plug(contextMenu);
   } else if (firstItem->getObject()->getType() == KFTPQueue::QueueObject::Site) {
@@ -570,7 +577,7 @@
     QPtrList<QListViewItem> selection = m_queue->selectedItems();
     for (QListViewItem *item = selection.first(); item; item = selection.next()) {
       if (item && static_cast<QueueViewItem*>(item)->getObject())
-        KFTPQueue::Manager::self()->removeTransfer(static_cast<QueueViewItem*>(item)->getObject()->getId());
+        KFTPQueue::Manager::self()->removeTransfer(static_cast<KFTPQueue::Transfer*>(static_cast<QueueViewItem*>(item)->getObject()));
     }
     
     KFTPQueue::Manager::self()->setEmitUpdate(true);
@@ -590,42 +597,41 @@
   QPtrList<QListViewItem> selection = m_queue->selectedItems();
   
   for (QListViewItem *item = selection.first(); item; item = selection.next()) {
-    // Move the listview item
-    // XXX: Is there a better/faster way to do this?
-    QListViewItem *newItemPos = 0, *prevItem;
-    
-    if (item->parent())
-      prevItem = item->parent()->firstChild();
-    else
-      prevItem = m_queue->firstChild();
-      
-    for (QListViewItem *i = prevItem; i; i = i->nextSibling()) {
-      if (i == item) {
-        m_queue->moveItem(item, item->parent(), newItemPos);
-        break;
-      }
-      
-      newItemPos = prevItem;
-    }
-    
     // Move the transfer
-    KFTPQueue::Manager::self()->moveTransferUp(static_cast<QueueViewItem*>(item)->getObject()->getId());
+    KFTPQueue::Manager::self()->moveTransferUp(static_cast<QueueViewItem*>(item)->getObject());
   }
 }
 
 void QueueView::slotMoveDown()
 {
   QPtrList<QListViewItem> selection = m_queue->selectedItems();
+  
   for (QListViewItem *item = selection.last(); item; item = selection.prev()) {
-    // Move the listview item
-    QListViewItem *below = item->nextSibling();
-    m_queue->moveItem(item, item->parent(), below);
-    
     // Move the transfer
-    KFTPQueue::Manager::self()->moveTransferDown(static_cast<QueueViewItem*>(item)->getObject()->getId());
+    KFTPQueue::Manager::self()->moveTransferDown(static_cast<QueueViewItem*>(item)->getObject());
   }
 }
 
+void QueueView::slotMoveTop()
+{
+  QPtrList<QListViewItem> selection = m_queue->selectedItems();
+  
+  for (QListViewItem *item = selection.first(); item; item = selection.next()) {
+    // Move the transfer
+    KFTPQueue::Manager::self()->moveTransferTop(static_cast<QueueViewItem*>(item)->getObject());
+  }
+}
+
+void QueueView::slotMoveBottom()
+{
+  QPtrList<QListViewItem> selection = m_queue->selectedItems();
+  
+  for (QListViewItem *item = selection.first(); item; item = selection.next()) {
+    // Move the transfer
+    KFTPQueue::Manager::self()->moveTransferBottom(static_cast<QueueViewItem*>(item)->getObject());
+  }
+}
+
 void QueueView::slotEdit()
 {
   QueueEditor *editor = new QueueEditor(this);
--- trunk/extragear/network/kftpgrabber/src/widgets/queueview/queueview.h #589827:589828
@@ -100,6 +100,8 @@
     KAction *m_removeAllAction;
     KAction *m_moveUpAction;
     KAction *m_moveDownAction;
+    KAction *m_moveTopAction;
+    KAction *m_moveBottomAction;
     KAction *m_editAction;
     
     // Toolbar Actions
@@ -139,6 +141,8 @@
     void slotRemoveAll();
     void slotMoveUp();
     void slotMoveDown();
+    void slotMoveTop();
+    void slotMoveBottom();
     void slotEdit();
     
     void slotLoad();