Bug 233171 - singleclick in amarok's filebrowser appends track to the playlist
Summary: singleclick in amarok's filebrowser appends track to the playlist
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: File Browser (show other bugs)
Version: 2.3.0
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-03 15:07 UTC by Florian Reinhard
Modified: 2010-06-13 23:01 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 2.3.2


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Reinhard 2010-04-03 15:07:25 UTC
Version:           2.3.0 (using 4.4.2 (KDE 4.4.2), Kubuntu packages)
Compiler:          cc
OS:                Linux (i686) release 2.6.32-19-generic

clicking on a file in amarok's built in filebrowser appends the track immediately to the playlist. a doubleclick should, but a single click should just select the file.
Comment 1 Sven Krohlas 2010-04-04 12:33:03 UTC
I can verify this.
Comment 2 Rick W. Chen 2010-06-13 19:20:27 UTC
commit 6fbcc4555f6786ce061df96772d98620eb1b65db
Author: Rick W. Chen <stuffcorpse@archlinux.us>
Date:   Fri Jun 11 20:12:27 2010 +1200

    Select tracks first in the file browser in single-click mode
    
    Previously, a single click on a track will append&play it. This overrides
    the behaviour for single-clicks in KDE single-click mode so that it
    actually behave more like double-click mode.
    
    Perhaps it is better to decide how single and double-click modes are
    handled, what happens when an item is activated, what actions to take
    for different types of items, etc. Then it can be implemented inside our
    PrettyViews so that all the specialized views can handle mouse clicks more
    consistently.
    
    BUG: 233171
    CCMAIL: amarok-devel@kde.org

diff --git a/ChangeLog b/ChangeLog
index 83acf49..6e84215 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -28,6 +28,8 @@ VERSION 2.3.2-Beta 1
       Patch by Richard Longland <rlongland@hotmail.com>.
 
   BUGFIXES:
+    * Single clicking a file in the file browser now selects it instead of
+      appending to the playlist by default in single-click mode. (BR 233171)
     * Fixed resizing and eliding issues with the file browser breadcrumbs.
       (BR 231366 comment #5)
     * Drop file icons in file browser breadcrumbs. (BR 231366)
diff --git a/src/browsers/filebrowser/FileView.cpp b/src/browsers/filebrowser/FileView.cpp
index 94dfec4..4e383fe 100644
--- a/src/browsers/filebrowser/FileView.cpp
+++ b/src/browsers/filebrowser/FileView.cpp
@@ -75,15 +75,13 @@ FileView::FileView( QWidget * parent )
 }
 
 void
-FileView::contextMenuEvent ( QContextMenuEvent * e )
+FileView::contextMenuEvent( QContextMenuEvent *e )
 {
-
     DEBUG_BLOCK
 
     if( !model() )
         return;
 
-
     //trying to do fancy stuff while showing places only leads to tears!
     debug() << model()->objectName();
     if( model()->objectName() == "PLACESMODEL" )
@@ -91,20 +89,14 @@ FileView::contextMenuEvent ( QContextMenuEvent * e )
         e->accept();
         return;
     }
-    
 
     QModelIndexList indices = selectedIndexes();
-
     // Abort if nothing is selected
     if( indices.isEmpty() )
         return;
 
-    
-
     KMenu* menu = new KMenu( this );
-
     QList<QAction *> actions = actionsForIndices( indices );
-
     foreach( QAction * action, actions )
         menu->addAction( action );
 
@@ -148,6 +140,61 @@ FileView::contextMenuEvent ( QContextMenuEvent * e )
 }
 
 void
+FileView::mouseReleaseEvent( QMouseEvent *event )
+{
+    QModelIndex index = indexAt( event->pos() );
+    if( !index.isValid() )
+    {
+        m_lastSelectedIndex = QModelIndex();
+        event->accept();
+        return;
+    }
+
+    QModelIndexList indices = selectedIndexes();
+    if( indices.count() == 1 && KGlobalSettings::singleClick() )
+    {
+        KFileItem item = index.data( KDirModel::FileItemRole ).value<KFileItem>();
+        if( item.isDir() )
+        {
+            m_lastSelectedIndex = QModelIndex();
+            Amarok::PrettyTreeView::mouseReleaseEvent( event );
+            return;
+        }
+
+        // check if the last selected item was clicked again, if so then trigger editor
+        if( m_lastSelectedIndex != index )
+        {
+            m_lastSelectedIndex = index;
+        }
+        else
+        {
+            Amarok::PrettyTreeView::edit( index, QAbstractItemView::AllEditTriggers, event );
+            m_lastSelectedIndex = QModelIndex();
+        }
+        event->accept();
+    }
+    else
+    {
+        m_lastSelectedIndex = QModelIndex();
+        Amarok::PrettyTreeView::mouseReleaseEvent( event );
+    }
+}
+
+void
+FileView::mouseDoubleClickEvent( QMouseEvent *event )
+{
+    m_lastSelectedIndex = QModelIndex();
+    QModelIndex index = indexAt( event->pos() );
+    if( !index.isValid() )
+    {
+        event->accept();
+        return;
+    }
+    emit activated( index );
+    event->accept();
+}
+
+void
 FileView::slotAppendToPlaylist()
 {
     addSelectionToPlaylist( false );
@@ -285,8 +332,6 @@ FileView::slotMoveTracks( const Meta::TrackList& tracks )
     m_moveAction = 0;
 }
 
-
-
 QList<QAction *>
 FileView::actionsForIndices( const QModelIndexList &indices )
 {
@@ -368,11 +413,11 @@ FileView::addSelectionToPlaylist( bool replace )
     The::playlistController()->insertOptioned( urls, replace ? Playlist::Replace : Playlist::AppendAndPlay );
 }
 
-
 void
 FileView::startDrag( Qt::DropActions supportedActions )
 {
     DEBUG_BLOCK
+    m_lastSelectedIndex = QModelIndex();
 
     //setSelectionMode( QAbstractItemView::NoSelection );
     // When a parent item is dragged, startDrag() is called a bunch of times. Here we prevent that:
@@ -435,8 +480,6 @@ FileView::selectedItems() const
     return items;
 }
 
-
-
 Meta::TrackList
 FileView::tracksForEdit() const
 {
diff --git a/src/browsers/filebrowser/FileView.h b/src/browsers/filebrowser/FileView.h
index 27057d3..eacd469 100644
--- a/src/browsers/filebrowser/FileView.h
+++ b/src/browsers/filebrowser/FileView.h
@@ -56,10 +56,10 @@ class CollectionAction : public QAction
 class FileView : public Amarok::PrettyTreeView
 {
     Q_OBJECT
+
 public:
     FileView( QWidget * parent );
 
-
 protected slots:
 
     void slotAppendToPlaylist();
@@ -72,12 +72,13 @@ protected slots:
     void slotDelete();
 
 protected:
-            
     QList<QAction *> actionsForIndices( const QModelIndexList &indices );
     void addSelectionToPlaylist( bool replace );
     
-    virtual void contextMenuEvent ( QContextMenuEvent * e );
-    void startDrag( Qt::DropActions supportedActions );
+    virtual void contextMenuEvent( QContextMenuEvent *e );
+    virtual void mouseReleaseEvent( QMouseEvent *event );
+    virtual void mouseDoubleClickEvent( QMouseEvent *event );
+    virtual void startDrag( Qt::DropActions supportedActions );
     KFileItemList selectedItems() const;
 
 private:
@@ -96,6 +97,7 @@ private:
     bool m_copyActivated;
     CollectionAction* m_moveAction;
     CollectionAction* m_copyAction;
+    QPersistentModelIndex m_lastSelectedIndex;
 };
 
 #endif // end include guard