Commit 849d5bbe authored by Max Howell's avatar Max Howell

This is Filelight beta7, sorry that I have not been updating CVS, it is mainly...

This is Filelight beta7, sorry that I have not been updating CVS, it is mainly because I like to rearrange source files and rename files frequently and CVS just sucks for this as we all know.
I didn't want to cvs remove the Makefile.am files, I wanted that cvs history, but cervisia doesn't cancel remove operations when you press escape, it does them anyway! Bug reported but that doesn't save my history! grumble.

svn path=/trunk/kdenonbeta/filelight/; revision=373143
parent 7976a14d
......@@ -8,7 +8,7 @@ fine as does GNU tar.
The configure script is provided (at some byte-cost!) so the procedure
should be as simple as:
./configure --prefix `kde-config --prefix`
./configure
make
su
make install
......@@ -26,14 +26,17 @@ email me if you're stuck, and I'd even appreciate email if you had
problems but found out how to get round them; this way I can improve
Filelight.
Homepage: http://www.methylblue.com/filelight/
Forums: http://www.methylblue.com/forum/
Email: filelight@methylblue.com.
If your compile fails and you used Linux please try the autopackage, it is a
distribution-neutral binary wrapped in a graphical installer. It is very nice.
http://www.methylblue.com/filelight/#packages
Generic instructions follow, enjoy Filelight!
Max Howell (max.howell@methylblue.com)
Max Howell
Homepage: http://www.methylblue.com/filelight/
Email: filelight@methylblue.com.
......@@ -79,7 +82,7 @@ The simplest way to compile this package is:
documentation.
4. You can remove the program binaries and object files from the
source code directory by typing `make clean'.
source code directory by typing `make clean'.
Compilers and Options
=====================
......
SUBDIRS = app part
INCLUDES = $(all_includes)
METASOURCES = AUTO
INCLUDES = $(all_includes) -I$(top_srcdir)/filelight/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)
//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 better to be safe
KAction::setEnabled( false );
}
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"
//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;
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()
{
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;
}
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
//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 ), VERSION,
I18N_NOOP( "Graphical disk-usage information" ), KAboutData::License_GPL_V2,
I18N_NOOP( "(C) 2003 Max Howell" ), "",
"http://www.methylblue.com/filelight/", "filelight@methylblue.com" );
int main( int argc, char *argv[] )
{
using Filelight::MainWindow;
about.addAuthor( "Max Howell", I18N_NOOP("Me"), "max.howell@methylblue.com", "http://www.methylblue.com/" );
about.addAuthor( "Mike Diehl", I18N_NOOP("Handbook guru"), 0, 0 );
//TODO complete this list!
about.addCredit( "Steffen Gerlach", I18N_NOOP("Inspiration"), 0, "http://www.steffengerlach.de/" );
about.addCredit( "André Somers", I18N_NOOP("Internationalisation support") );
about.addCredit( "Stephanie James", I18N_NOOP("\"Girlfriend usability-testing\"") );
about.addCredit( "Marcus Camen", I18N_NOOP("Bravery in the face of unreadable code (patches)") );
about.addCredit( "Kevin Donnelly", I18N_NOOP("Welsh Translation") );
about.addCredit( "Marcel Meyer", I18N_NOOP("German Translation, testing, bug reports and suggestions") );
about.addCredit( "Michal Sulek", I18N_NOOP("Slovak Translation") );
about.addCredit( "Michal Kosmulski", I18N_NOOP("Polish Translation") );
about.addCredit( "Andy Teijelo Pérez",I18N_NOOP("Spanish Translation") );
about.addCredit( "Virgile Gerecke", I18N_NOOP("French Translation") );
about.addCredit( "Nick Shafff", I18N_NOOP("Russian Translation") );
about.addCredit( "Rinse de Vries", I18N_NOOP("Dutch Translation") );
KCmdLineArgs::init( argc, argv, &about );
KCmdLineArgs::addCmdLineOptions( options ); // Add our own 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();
}
//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 <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 <kstatusbar.h>
#include <ktoolbar.h>
#include <kurl.h>
#include <kurlcompletion.h> //locationbar
#include <stdlib.h> //std::exit()
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?
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" );
statusBar()->message( i18n( "Use the Scan-menu to begin..." ) );
}
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 = m_combo->lineEdit()->text();
if( slotScanPath( path ) )
m_combo->addToHistory( path );
}
inline bool
MainWindow::slotScanPath( const QString &path )
{
return slotScanUrl( KURL::fromPathOrURL( path ) );
}
/*inline */bool //FIXME you may have to move this to the header :(
MainWindow::slotScanUrl( const KURL &url )
{
const KURL oldUrl = m_part->url();
const bool b = m_part->openURL( url );
if( b ) {
m_histories->push( oldUrl );
actionCollection()->action( "go_back" )->KAction::setEnabled( false ); } //FIXME
return b;
}
inline void
MainWindow::slotAbortScan()
{
if( m_part->closeURL() ) actionCollection()->action( "scan_stop" )->setEnabled( false );
}
inline void
MainWindow::scanStarted()
{
stateChanged( "scan_started" );
m_combo->clearFocus();
}
inline void
MainWindow::scanFailed()
{
stateChanged( "scan_failed" );
actionCollection()->action( "go_up" )->setText( i18n( "Up" ) );
m_combo->lineEdit()->clear();
}
void
MainWindow::scanCompleted()
{
KAction *goUp = actionCollection()->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 );
goUp->setText( i18n( "Up" ) );
}
else goUp->setText( i18n( "Up: %1" ).arg( 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
#include "mainWindow.moc"
/***************************************************************************
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
/***************************************************************************
define.h - description
-------------------
begin : Tue Sep 23 2003
copyright : (C) 2003 by Max Howell
email : max.howell@methylblue.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
//Author: Max Howell <max.howell@methylblue.com>, (C) 2003-4
//Copyright: See COPYING file that comes with this distribution
#ifndef DEFINE_H
#define DEFINE_H
#ifndef PI