diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-03 01:26:04 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-03 01:26:04 +0000 |
commit | 3c7b870f367df150ea60eb9d6bb2fd41646545d7 (patch) | |
tree | ac8705b4703cebb5031f9443eafd3e429a17ac1a /src/app | |
download | filelight-3c7b870f367df150ea60eb9d6bb2fd41646545d7.tar.gz filelight-3c7b870f367df150ea60eb9d6bb2fd41646545d7.zip |
Added abandoned Filelight application
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/filelight@1084392 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/Makefile.am | 8 | ||||
-rw-r--r-- | src/app/historyAction.cpp | 96 | ||||
-rw-r--r-- | src/app/historyAction.h | 64 | ||||
-rw-r--r-- | src/app/main.cpp | 55 | ||||
-rw-r--r-- | src/app/mainWindow.cpp | 280 | ||||
-rw-r--r-- | src/app/mainWindow.h | 83 |
6 files changed, 586 insertions, 0 deletions
diff --git a/src/app/Makefile.am b/src/app/Makefile.am new file mode 100644 index 0000000..d0ae17d --- /dev/null +++ b/src/app/Makefile.am @@ -0,0 +1,8 @@ +INCLUDES = $(all_includes) -I$(top_srcdir)/src +METASOURCES = AUTO + +# Application +bin_PROGRAMS = filelight +filelight_SOURCES = historyAction.cpp mainWindow.cpp main.cpp +filelight_LDADD = $(LIB_KPARTS) $(LIB_KDEUI) +filelight_LDFLAGS = $(all_libraries) $(KDE_RPATH) diff --git a/src/app/historyAction.cpp b/src/app/historyAction.cpp new file mode 100644 index 0000000..bf715cb --- /dev/null +++ b/src/app/historyAction.cpp @@ -0,0 +1,96 @@ +//Author: Max Howell <max.howell@methylblue.com>, (C) 2003-4 +//Copyright: See COPYING file that comes with this distribution + +#include "historyAction.h" + +#include <kaccel.h> +#include <kconfig.h> +#include <klocale.h> + + +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 ) +{ + // 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 ) +{ + connect( m_b, SIGNAL(activated()), SLOT(pop()) ); + connect( m_f, SIGNAL(activated()), SLOT(pop()) ); +} + +void +HistoryCollection::push( const KURL &url ) //slot +{ + if( !url.isEmpty() ) + { + if( !m_receiver ) + { + m_f->clear(); + m_receiver = m_b; + } + + m_receiver->push( url.path( 1 ) ); + } + m_receiver = 0; +} + +void +HistoryCollection::pop() //slot +{ + KURL url; + const QString path = ((HistoryAction*)sender())->pop(); //FIXME here we remove the constness + url.setPath( path ); + + m_receiver = (sender() == m_b) ? m_f : m_b; + + emit activated( url ); +} + +void +HistoryCollection::save( KConfig *config ) +{ + config->writePathEntry( "backHistory", m_b->m_list ); + config->writePathEntry( "forwardHistory", m_f->m_list ); +} + +void +HistoryCollection::restore( KConfig *config ) +{ + m_b->m_list = config->readPathListEntry( "backHistory" ); + m_f->m_list = config->readPathListEntry( "forwardHistory" ); + //TODO texts are not updated - no matter +} + +#include "historyAction.moc" diff --git a/src/app/historyAction.h b/src/app/historyAction.h new file mode 100644 index 0000000..773093c --- /dev/null +++ b/src/app/historyAction.h @@ -0,0 +1,64 @@ +//Author: Max Howell <max.howell@methylblue.com>, (C) 2003-4 +//Copyright: See COPYING file that comes with this distribution + +#ifndef HISTORYACTION_H +#define HISTORYACTION_H + +#include <kaction.h> +#include <kurl.h> +#include <qstringlist.h> + +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 ); + + friend class HistoryCollection; + +public: + virtual void setEnabled( bool b = true ) { KAction::setEnabled( b ? !m_list.isEmpty() : false ); } + + void clear() { m_list.clear(); KAction::setText( m_text ); } + +private: + void setText(); + + void push( const QString &path ); + QString pop(); + + const QString m_text; + QStringList m_list; +}; + + +class HistoryCollection : public QObject +{ +Q_OBJECT + +public: + HistoryCollection( KActionCollection *ac, QObject *parent, const char *name ); + + void save( KConfig *config ); + void restore( KConfig *config ); + +public slots: + void push( const KURL& ); + void stop() { m_receiver = 0; } + +signals: + void activated( const KURL& ); + +private slots: + void pop(); + +private: + HistoryAction *m_b, *m_f, *m_receiver; +}; + +#endif diff --git a/src/app/main.cpp b/src/app/main.cpp new file mode 100644 index 0000000..17e6989 --- /dev/null +++ b/src/app/main.cpp @@ -0,0 +1,55 @@ +//Author: Max Howell <max.howell@methylblue.com>, (C) 2003-4 +//Copyright: See COPYING file that comes with this distribution + +#include "define.h" +#include <kaboutdata.h> +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <klocale.h> +#include <kurl.h> +#include "mainWindow.h" + + +static const KCmdLineOptions options[] = +{ + { "+[path]", I18N_NOOP( "Scan 'path'" ), 0 }, + { 0, 0, 0 } +}; + +static KAboutData about( + APP_NAME, I18N_NOOP( APP_PRETTYNAME ), APP_VERSION, + I18N_NOOP("Graphical disk-usage information"), KAboutData::License_GPL_V2, + I18N_NOOP("(C )2006 Max Howell"), 0, + "http://www.methylblue.com/filelight/", "filelight@methylblue.com" ); + + +int main( int argc, char *argv[] ) +{ + using Filelight::MainWindow; + + about.addAuthor( "Max Howell", I18N_NOOP("Author, maintainer"), "max.howell@methylblue.com", "http://www.methylblue.com/" ); + about.addAuthor( "Mike Diehl", I18N_NOOP("Documentation"), 0, 0 ); + about.addCredit( "Steffen Gerlach", I18N_NOOP("Inspiration"), 0, "http://www.steffengerlach.de/" ); + about.addCredit( "André Somers", I18N_NOOP("Internationalization") ); + about.addCredit( "Stephanie James", I18N_NOOP("Testing") ); + about.addCredit( "Marcus Camen", I18N_NOOP("Bravery in the face of unreadable code") ); + + KCmdLineArgs::init( argc, argv, &about ); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + if (!app.isRestored()) { + MainWindow *mw = new MainWindow(); + app.setMainWidget( mw ); + + KCmdLineArgs* const args = KCmdLineArgs::parsedArgs(); + if (args->count() > 0 ) mw->scan( args->url( 0 )); + args->clear(); + + mw->show(); + } + else RESTORE( MainWindow ); + + return app.exec(); +} diff --git a/src/app/mainWindow.cpp b/src/app/mainWindow.cpp new file mode 100644 index 0000000..155ece0 --- /dev/null +++ b/src/app/mainWindow.cpp @@ -0,0 +1,280 @@ +//Author: Max Howell <max.howell@methylblue.com>, (C) 2003-4 +//Copyright: See COPYING file that comes with this distribution + +#include "mainWindow.h" +#include "part/part.h" +#include "historyAction.h" + +#include <cstdlib> //std::exit() +#include <kaccel.h> //KStdAccel namespace +#include <kaction.h> +#include <kapplication.h> //setupActions() +#include <kcombobox.h> //locationbar +#include <kconfig.h> +#include <kdirselectdialog.h> //slotScanDirectory +#include <kedittoolbar.h> //for editToolbar dialog +#include <kkeydialog.h> +#include <klibloader.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kshell.h> +#include <kstatusbar.h> +#include <ktoolbar.h> +#include <kurl.h> +#include <kurlcompletion.h> //locationbar +#include <qobjectlist.h> +#include <qpopupmenu.h> +#include <qtooltip.h> + + + +namespace Filelight { + +MainWindow::MainWindow() + : KParts::MainWindow() + , m_part( 0 ) +{ + KLibFactory *factory = KLibLoader::self()->factory( "libfilelight" ); + + if (!factory) { + KMessageBox::error( this, i18n("KDE could not find the Filelight Part, or the Filelight Part could not be started. Did you make install?") ); + //exit() seems to not exist inside the std namespace for some users! + using namespace std; + exit( 1 ); //don't use QApplication::exit() - it causes a crash + } + + m_part = (Part *)factory->create( this, "part", "KParts::ReadOnlyPart" ); + + setCentralWidget( m_part->widget() ); + setStandardToolBarMenuEnabled( true ); + setupActions(); + createGUI( m_part ); + + stateChanged( "scan_failed" ); //bah! doesn't affect the parts' actions, should I add them to the actionCollection here? + + QObjectList *buttons = toolBar()->queryList( "KToolBarButton" ); + if (buttons->isEmpty()) + KMessageBox::error( this, i18n("Filelight is not installed properly, consequently its menus and toolbars will appear reduced or even empty") ); + delete buttons; + + connect( m_part, SIGNAL(started( KIO::Job* )), SLOT(scanStarted()) ); + connect( m_part, SIGNAL(completed()), SLOT(scanCompleted()) ); + connect( m_part, SIGNAL(canceled( const QString& )), SLOT(scanFailed()) ); + + //TODO test these + connect( m_part, SIGNAL(canceled( const QString& )), m_histories, SLOT(stop()) ); + connect( BrowserExtension::childObject( m_part ), SIGNAL(openURLNotify()), SLOT(urlAboutToChange()) ); + + KConfig* const config = KGlobal::config(); + config->setGroup( "general" ); + m_combo->setHistoryItems( config->readPathListEntry( "comboHistory" ) ); + applyMainWindowSettings( config, "window" ); +} + +inline void +MainWindow::setupActions() //singleton function +{ + KActionCollection *const ac = actionCollection(); + + m_combo = new KHistoryCombo( this, "history_combo" ); + m_combo->setCompletionObject( new KURLCompletion( KURLCompletion::DirCompletion ) ); + m_combo->setAutoDeleteCompletionObject( true ); + m_combo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + m_combo->setDuplicatesEnabled( false ); + + KStdAction::open( this, SLOT(slotScanDirectory()), ac, "scan_directory" ); + KStdAction::quit( this, SLOT(close()), ac ); + KStdAction::up( this, SLOT(slotUp()), ac ); + KStdAction::configureToolbars(this, SLOT(configToolbars()), ac); + KStdAction::keyBindings(this, SLOT(configKeys()), ac); + + new KAction( i18n( "Scan &Home Directory" ), "folder_home", CTRL+Key_Home, this, SLOT(slotScanHomeDirectory()), ac, "scan_home" ); + new KAction( i18n( "Scan &Root Directory" ), "folder_red", 0, this, SLOT(slotScanRootDirectory()), ac, "scan_root" ); + new KAction( i18n( "Rescan" ), "reload", KStdAccel::reload(), m_part, SLOT(rescan()), ac, "scan_rescan" ); + new KAction( i18n( "Stop" ), "stop", Qt::Key_Escape, this, SLOT(slotAbortScan()), ac, "scan_stop" ); + new KAction( i18n( "Clear Location Bar" ), KApplication::reverseLayout() ? "clear_left" : "locationbar_erase", 0, m_combo, SLOT(clearEdit()), ac, "clear_location" ); + new KAction( i18n( "Go" ), "key_enter", 0, m_combo, SIGNAL(returnPressed()), ac, "go" ); + + KWidgetAction *combo = new KWidgetAction( m_combo, i18n( "Location Bar" ), 0, 0, 0, ac, "location_bar" ); + m_recentScans = new KRecentFilesAction( i18n( "&Recent Scans" ), 0, ac, "scan_recent", 8 ); + m_histories = new HistoryCollection( ac, this, "history_collection" ); + + ac->action( "scan_directory" )->setText( i18n( "&Scan Directory..." ) ); + m_recentScans->loadEntries( KGlobal::config() ); + combo->setAutoSized( true ); //FIXME what does this do? + + connect( m_recentScans, SIGNAL(urlSelected( const KURL& )), SLOT(slotScanUrl( const KURL& )) ); + connect( m_combo, SIGNAL(returnPressed()), SLOT(slotComboScan()) ); + connect( m_histories, SIGNAL(activated( const KURL& )), SLOT(slotScanUrl( const KURL& )) ); +} + +bool +MainWindow::queryExit() +{ + if( !m_part ) //apparently std::exit() still calls this function, and abort() causes a crash.. + return true; + + KConfig* const config = KGlobal::config(); + + saveMainWindowSettings( config, "window" ); + m_recentScans->saveEntries( config ); + config->setGroup( "general" ); + config->writePathEntry( "comboHistory", m_combo->historyItems() ); + config->sync(); + + return true; +} + +inline void +MainWindow::configToolbars() //slot +{ + KEditToolbar dialog( factory(), this ); + dialog.showButtonApply( false ); + + if( dialog.exec() ) + { + createGUI( m_part ); + applyMainWindowSettings( kapp->config(), "window" ); + } +} + +inline void +MainWindow::configKeys() //slot +{ + KKeyDialog::configure( actionCollection(), this ); +} + +inline void +MainWindow::slotScanDirectory() +{ + slotScanUrl( KDirSelectDialog::selectDirectory( m_part->url().path(), false, this ) ); +} + +inline void MainWindow::slotScanHomeDirectory() { slotScanPath( getenv( "HOME" ) ); } +inline void MainWindow::slotScanRootDirectory() { slotScanPath( "/" ); } +inline void MainWindow::slotUp() { slotScanUrl( m_part->url().upURL() ); } + +inline void +MainWindow::slotComboScan() +{ + const QString path = KShell::tildeExpand(m_combo->lineEdit()->text()); + if (slotScanPath( path )) + m_combo->addToHistory( path ); +} + +inline bool +MainWindow::slotScanPath( const QString &path ) +{ + return slotScanUrl( KURL::fromPathOrURL( path ) ); +} + +bool +MainWindow::slotScanUrl( const KURL &url ) +{ + const KURL oldUrl = m_part->url(); + const bool b = m_part->openURL( url ); + + if (b) { + m_histories->push( oldUrl ); + action( "go_back" )->KAction::setEnabled( false ); } //FIXME + + return b; +} + +inline void +MainWindow::slotAbortScan() +{ + if( m_part->closeURL() ) action( "scan_stop" )->setEnabled( false ); +} + +inline void +MainWindow::scanStarted() +{ + stateChanged( "scan_started" ); + m_combo->clearFocus(); +} + +inline void +MainWindow::scanFailed() +{ + stateChanged( "scan_failed" ); + setActionMenuTextOnly( action( "go_up" ), QString::null ); + m_combo->lineEdit()->clear(); +} + +void +MainWindow::scanCompleted() +{ + 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 ) == "/") { + goUp->setEnabled( false ); + setActionMenuTextOnly( goUp, QString() ); + } + else + setActionMenuTextOnly( goUp, url.upURL().path( 1 ) ); + + m_recentScans->addURL( url ); //FIXME doesn't set the tick +} + +inline void +MainWindow::urlAboutToChange() +{ + //called when part's URL is about to change internally + //the part will then create the Map and emit completed() + + m_histories->push( m_part->url() ); +} + + +/********************************************** + SESSION MANAGEMENT + **********************************************/ + +void +MainWindow::saveProperties( KConfig *config ) //virtual +{ + m_histories->save( config ); + config->writeEntry( "currentMap", m_part->url().path() ); +} + +void +MainWindow::readProperties( KConfig *config ) //virtual +{ + m_histories->restore( config ); + slotScanPath( config->readEntry( "currentMap", QString::null ) ); +} + +} //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" diff --git a/src/app/mainWindow.h b/src/app/mainWindow.h new file mode 100644 index 0000000..87001c8 --- /dev/null +++ b/src/app/mainWindow.h @@ -0,0 +1,83 @@ +/*************************************************************************** + filelight.h - description + ------------------- + begin : Mon May 12 22:38:30 BST 2003 + copyright : (C) 2003 by Max Howell + email : mh9193@bris.ac.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef FILELIGHT_H +#define FILELIGHT_H + +#include <kparts/mainwindow.h> + +class KSqueezedTextLabel; +class KHistoryCombo; +class KAction; +class KRecentFilesAction; + +class ScanProgressBox; +class HistoryCollection; + + +namespace Filelight { + +class Part; + +class MainWindow : public KParts::MainWindow +{ + Q_OBJECT + + public: + MainWindow(); + + void scan( const KURL &u ) { slotScanUrl( u ); } + + private slots: + void slotUp(); + void slotComboScan(); + void slotScanDirectory(); + void slotScanHomeDirectory(); + void slotScanRootDirectory(); + bool slotScanUrl( const KURL& ); + bool slotScanPath( const QString& ); + void slotAbortScan(); + + void configToolbars(); + void configKeys(); + + void scanStarted(); + void scanFailed(); + void scanCompleted(); + + void urlAboutToChange(); + + protected: + virtual void saveProperties( KConfig * ); + virtual void readProperties( KConfig * ); + virtual bool queryExit(); + + private: + Filelight::Part *m_part; + + KSqueezedTextLabel *m_status[2]; + KHistoryCombo *m_combo; + HistoryCollection *m_histories; + KRecentFilesAction *m_recentScans; + + void setupStatusBar(); + void setupActions(); +}; + +} // namespace Filelight + +#endif |