[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/utils/filelight/src
From:       Max Howell <max.howell () methylblue ! com>
Date:       2006-08-15 22:34:28
Message-ID: 1155681268.402111.15489.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 573384 by mhowell:

For those of us who like toolbars with text under the icons, (If you
don't use this, you should, it's really nice in many ways), don't add
the destination url to the toolbar text, just the toolbar tooltip and
menu item string. Smart.


 M  +29 -7     app/historyAction.cpp  
 M  +8 -23     app/historyAction.h  
 M  +43 -15    app/mainWindow.cpp  
 M  +2 -2      part/localLister.cpp  


--- trunk/extragear/utils/filelight/src/app/historyAction.cpp #573383:573384
@@ -10,19 +10,41 @@
 
 inline
 HistoryAction::HistoryAction( const QString &text, const char *icon, const KShortcut \
                &cut, KActionCollection *ac, const char *name )
-  : KAction( text, icon, cut, 0, 0, ac, name )
-  , m_text( text )
+        : KAction( text, icon, cut, 0, 0, ac, name )
+        , m_text( text )
 {
-    //ui files make this false, but better to be safe
+    // ui files make this false, but we can't rely on UI file as it isn't compiled \
in :(  KAction::setEnabled( false );
 }
 
+void
+HistoryAction::push( const QString &path )
+{
+    if( !path.isEmpty() && m_list.last() != path )
+    {
+        m_list.append( path );
+        setActionMenuTextOnly( this, path );
+        KAction::setEnabled( true );
+    }
+}
 
+QString
+HistoryAction::pop()
+{
+    const QString s = m_list.last();
+    m_list.pop_back();
+    setActionMenuTextOnly( this, m_list.last() );
+    setEnabled();
+    return s;
+}
+
+
+
 HistoryCollection::HistoryCollection( KActionCollection *ac, QObject *parent, const \
                char *name )
-  : QObject( parent, name )
-  , m_b( new HistoryAction( i18n( "Back" ), "back", KStdAccel::back(), ac, "go_back" \
                ) )
-  , m_f( new HistoryAction( i18n( "Forward" ), "forward",  KStdAccel::forward(), ac, \
                "go_forward" ) )
-  , m_receiver( 0 )
+        : QObject( parent, name )
+        , m_b( new HistoryAction( i18n( "Back" ), "back", KStdAccel::back(), ac, \
"go_back" ) ) +        , m_f( new HistoryAction( i18n( "Forward" ), "forward",  \
KStdAccel::forward(), ac, "go_forward" ) ) +        , m_receiver( 0 )
 {
     connect( m_b, SIGNAL(activated()), SLOT(pop()) );
     connect( m_f, SIGNAL(activated()), SLOT(pop()) );
--- trunk/extragear/utils/filelight/src/app/historyAction.h #573383:573384
@@ -11,6 +11,10 @@
 class KConfig;
 
 
+/// defined in mainWindow.cpp
+void setActionMenuTextOnly( KAction *a, QString const &suffix );
+
+
 class HistoryAction : KAction
 {
     HistoryAction( const QString &text, const char *icon, const KShortcut &cut, \
KActionCollection *ac, const char *name ); @@ -23,30 +27,11 @@
     void clear() { m_list.clear(); KAction::setText( m_text ); }
 
 private:
-    void setText()
-    {
-        QString newText = m_text;
-        if( !m_list.isEmpty() ) { newText += ": "; newText += m_list.last(); }
-        KAction::setText( newText );
-    }
-    void push( const QString &path )
-    {
-        if( !path.isEmpty() && m_list.last() != path )
-        {
-            m_list.append( path );
-            setText();
-            KAction::setEnabled( true );
-        }
-    }
-    QString pop()
-    {
-        const QString s = m_list.last();
-        m_list.pop_back();
-        setText();
-        setEnabled();
-        return s;
-    }
+    void setText();
 
+    void push( const QString &path );
+    QString pop();
+
     const QString m_text;
     QStringList m_list;
 };
--- trunk/extragear/utils/filelight/src/app/mainWindow.cpp #573383:573384
@@ -5,6 +5,7 @@
 #include "part/part.h"
 #include "historyAction.h"
 
+#include <cstdlib>            //std::exit()
 #include <kaccel.h>           //KStdAccel namespace
 #include <kaction.h>
 #include <kapplication.h>     //setupActions()
@@ -21,12 +22,16 @@
 #include <ktoolbar.h>
 #include <kurl.h>
 #include <kurlcompletion.h>   //locationbar
-#include <stdlib.h>           //std::exit()
+#include <qtooltip.h>
+#include <qpopupmenu.h>
 
 
+
 namespace Filelight {
 
-MainWindow::MainWindow() : KParts::MainWindow(), m_part( 0 )
+MainWindow::MainWindow()
+        : KParts::MainWindow()
+        , m_part( 0 )
 {
     KLibFactory *factory = KLibLoader::self()->factory( "libfilelight" );
 
@@ -58,8 +63,6 @@
     config->setGroup( "general" );
     m_combo->setHistoryItems( config->readPathListEntry( "comboHistory" ) );
     applyMainWindowSettings( config, "window" );
-
-    statusBar()->message( i18n( "Use the Scan-menu to begin..." ) );
 }
 
 inline void
@@ -149,7 +152,7 @@
 MainWindow::slotComboScan()
 {
    const QString path = KShell::tildeExpand(m_combo->lineEdit()->text());
-   if( slotScanPath( path ) )
+   if (slotScanPath( path ))
       m_combo->addToHistory( path );
 }
 
@@ -159,15 +162,15 @@
    return slotScanUrl( KURL::fromPathOrURL( path ) );
 }
 
-/*inline */bool //FIXME you may have to move this to the header :(
+bool
 MainWindow::slotScanUrl( const KURL &url )
 {
    const KURL oldUrl = m_part->url();
    const bool b = m_part->openURL( url );
 
-   if( b ) {
+   if (b) {
       m_histories->push( oldUrl );
-      actionCollection()->action( "go_back" )->KAction::setEnabled( false ); } \
//FIXME +      action( "go_back" )->KAction::setEnabled( false ); } //FIXME
 
    return b;
 }
@@ -175,7 +178,7 @@
 inline void
 MainWindow::slotAbortScan()
 {
-    if( m_part->closeURL() ) actionCollection()->action( "scan_stop" )->setEnabled( \
false ); +    if( m_part->closeURL() ) action( "scan_stop" )->setEnabled( false );
 }
 
 inline void
@@ -189,26 +192,26 @@
 MainWindow::scanFailed()
 {
     stateChanged( "scan_failed" );
-    actionCollection()->action( "go_up" )->setText( i18n( "Up" ) );
+    setActionMenuTextOnly( action( "go_up" ), QString::null );
     m_combo->lineEdit()->clear();
 }
 
 void
 MainWindow::scanCompleted()
 {
-    KAction *goUp  = actionCollection()->action( "go_up" );
+    KAction *goUp  = action( "go_up" );
     const KURL url = m_part->url();
 
     stateChanged( "scan_complete" );
 
     m_combo->lineEdit()->setText( m_part->prettyURL() );
 
-    if( url.path( 1 ) == "/" )
-    {
+    if ( url.path( 1 ) == "/") {
         goUp->setEnabled( false );
-        goUp->setText( i18n( "Up" ) );
+        setActionMenuTextOnly( goUp, QString() );
     }
-    else goUp->setText( i18n( "Up: %1" ).arg( url.upURL().path( 1 ) ) );
+    else
+        setActionMenuTextOnly( goUp, url.upURL().path( 1 ) );
 
     m_recentScans->addURL( url ); //FIXME doesn't set the tick
 }
@@ -243,4 +246,29 @@
 
 } //namespace Filelight
 
+
+
+/// declared in historyAction.h
+
+void setActionMenuTextOnly( KAction *a, QString const &suffix )
+{
+    QString const menu_text = suffix.isEmpty()
+            ? a->text()
+            : i18n( "&Up: /home/mxcl", "%1: %2" ).arg( a->text(), suffix );
+
+    for (int i = 0; i < a->containerCount(); ++i) {
+        QWidget *w = a->container( i );
+        int const id = a->itemId( i );
+
+        if (w->inherits( "QPopupMenu" ))
+            static_cast<QPopupMenu*>(w)->changeItem( id, menu_text );
+
+        else if (w->inherits( "KToolBar" )) {
+            QWidget *button = static_cast<KToolBar*>(w)->getWidget( id );
+            if (button->inherits( "KToolBarButton" ))
+                QToolTip::add( button, suffix );
+        }
+    }
+}
+
 #include "mainWindow.moc"
--- trunk/extragear/utils/filelight/src/part/localLister.cpp #573383:573384
@@ -208,7 +208,7 @@
             }
 
             if( !d ) //then scan
-               if( d = scan( new_path, new_dirname ) ) //then scan was successful
+               if ((d = scan( new_path, new_dirname ))) //then scan was successful
                   cwd->append( d );
          }
 
@@ -236,11 +236,11 @@
 #ifdef HAVE_MNTENT_H
       struct mntent *mnt_ent;
 #endif
-      FILE *fp;
       QString str;
 
 
 #ifdef HAVE_MNTENT_H
+      FILE *fp;
       if( setfsent() == 0 || !( fp = setmntent( INFO_MOUNTED_PARTITIONS, "r" ) ) )
 #else
       if( setfsent() == 0 )


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic