diff options
Diffstat (limited to 'src/app/GUI')
-rw-r--r-- | src/app/GUI/Makefile.am | 18 | ||||
-rw-r--r-- | src/app/GUI/dirhistorybutton.cpp | 82 | ||||
-rw-r--r-- | src/app/GUI/dirhistorybutton.h | 57 | ||||
-rw-r--r-- | src/app/GUI/dirhistoryqueue.cpp | 87 | ||||
-rw-r--r-- | src/app/GUI/dirhistoryqueue.h | 48 | ||||
-rw-r--r-- | src/app/GUI/kcmdline.cpp | 253 | ||||
-rw-r--r-- | src/app/GUI/kcmdline.h | 101 | ||||
-rw-r--r-- | src/app/GUI/kcmdmodebutton.cpp | 74 | ||||
-rw-r--r-- | src/app/GUI/kcmdmodebutton.h | 53 | ||||
-rw-r--r-- | src/app/GUI/kfnkeys.cpp | 133 | ||||
-rw-r--r-- | src/app/GUI/kfnkeys.h | 55 | ||||
-rw-r--r-- | src/app/GUI/krremoteencodingmenu.cpp | 207 | ||||
-rw-r--r-- | src/app/GUI/krremoteencodingmenu.h | 68 | ||||
-rw-r--r-- | src/app/GUI/krusaderstatus.cpp | 46 | ||||
-rw-r--r-- | src/app/GUI/krusaderstatus.h | 57 | ||||
-rw-r--r-- | src/app/GUI/mediabutton.cpp | 692 | ||||
-rw-r--r-- | src/app/GUI/mediabutton.h | 107 | ||||
-rw-r--r-- | src/app/GUI/profilemanager.cpp | 198 | ||||
-rw-r--r-- | src/app/GUI/profilemanager.h | 70 | ||||
-rw-r--r-- | src/app/GUI/syncbrowsebutton.cpp | 72 | ||||
-rw-r--r-- | src/app/GUI/syncbrowsebutton.h | 67 |
21 files changed, 2545 insertions, 0 deletions
diff --git a/src/app/GUI/Makefile.am b/src/app/GUI/Makefile.am new file mode 100644 index 0000000..f7d9c9e --- /dev/null +++ b/src/app/GUI/Makefile.am @@ -0,0 +1,18 @@ +noinst_LIBRARIES = libGUI.a + +INCLUDES = $(all_includes) + +libGUI_a_METASOURCES = AUTO + +libGUI_a_SOURCES = \ + dirhistoryqueue.cpp \ + dirhistorybutton.cpp \ + krusaderstatus.cpp \ + kfnkeys.cpp \ + kcmdline.cpp \ + syncbrowsebutton.cpp \ + profilemanager.cpp \ + krremoteencodingmenu.cpp \ + mediabutton.cpp \ + kcmdmodebutton.cpp + diff --git a/src/app/GUI/dirhistorybutton.cpp b/src/app/GUI/dirhistorybutton.cpp new file mode 100644 index 0000000..a311b0a --- /dev/null +++ b/src/app/GUI/dirhistorybutton.cpp @@ -0,0 +1,82 @@ +/*************************************************************************** + dirhistorybutton.cpp - description + ------------------- + begin : Sun Jan 4 2004 + copyright : (C) 2004 by Shie Erlich & Rafi Yanai + email : +***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "dirhistorybutton.h" +#include "dirhistoryqueue.h" + +#include "../VFS/vfs.h" +#include <tqpopupmenu.h> +#include <tqdir.h> +#include <tdelocale.h> +#include <kiconloader.h> + +#include <kdebug.h> + +DirHistoryButton::DirHistoryButton( DirHistoryQueue* hQ, TQWidget *parent, const char *name ) : TQToolButton( parent, name ) { + TDEIconLoader * iconLoader = new TDEIconLoader(); + TQPixmap icon = iconLoader->loadIcon( "history", TDEIcon::Toolbar, 16 ); + + setFixedSize( icon.width() + 4, icon.height() + 4 ); + setPixmap( icon ); + setTextLabel( i18n( "Open the directory history list" ), true ); + setPopupDelay( 10 ); // 0.01 seconds press + setAcceptDrops( false ); + + popupMenu = new TQPopupMenu( this ); + TQ_CHECK_PTR( popupMenu ); + + setPopup( popupMenu ); + popupMenu->setCheckable( true ); + + historyQueue = hQ; + + connect( popupMenu, TQ_SIGNAL( aboutToShow() ), this, TQ_SLOT( slotAboutToShow() ) ); + connect( popupMenu, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( slotPopupActivated( int ) ) ); +} + +DirHistoryButton::~DirHistoryButton() {} + +void DirHistoryButton::openPopup() { + TQPopupMenu * pP = popup(); + if ( pP ) { + popup() ->exec( mapToGlobal( TQPoint( 0, height() ) ) ); + } +} +/** No descriptions */ +void DirHistoryButton::slotPopup() { + // kdDebug() << "History slot" << endl; +} +/** No descriptions */ +void DirHistoryButton::slotAboutToShow() { + // kdDebug() << "about to show" << endl; + popupMenu->clear(); + KURL::List::iterator it; + + int id = 0; + for ( it = historyQueue->urlQueue.begin(); it != historyQueue->urlQueue.end(); ++it ) { + popupMenu->insertItem( (*it).prettyURL(), id++ ); + } + if ( id > 0 ) { + popupMenu->setItemChecked( 0, true ); + } +} +/** No descriptions */ +void DirHistoryButton::slotPopupActivated( int id ) { + emit openUrl( historyQueue->urlQueue[ id ] ); +} + +#include "dirhistorybutton.moc" diff --git a/src/app/GUI/dirhistorybutton.h b/src/app/GUI/dirhistorybutton.h new file mode 100644 index 0000000..ae0da17 --- /dev/null +++ b/src/app/GUI/dirhistorybutton.h @@ -0,0 +1,57 @@ +/*************************************************************************** + dirhistorybutton.h - description + ------------------- + begin : Sun Jan 4 2004 + copyright : (C) 2004 by Shie Erlich & Rafi Yanai + email : + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 DIRHISTORYBUTTON_H +#define DIRHISTORYBUTTON_H + +#include <tqwidget.h> +#include <tqtoolbutton.h> +#include <kurl.h> + +class TQPopupMenu; +class DirHistoryQueue; + +/** + *@author Shie Erlich & Rafi Yanai + */ + +class DirHistoryButton : public TQToolButton { + TQ_OBJECT + +public: + DirHistoryButton(DirHistoryQueue* hQ, TQWidget *parent=0, const char *name=0); + ~DirHistoryButton(); + + void openPopup(); + +private: + TQPopupMenu* popupMenu; + DirHistoryQueue* historyQueue; + +public slots: // Public slots + /** No descriptions */ + void slotPopup(); + /** No descriptions */ + void slotAboutToShow(); + /** No descriptions */ + void slotPopupActivated(int id); +signals: // Signals + /** No descriptions */ + void openUrl(const KURL&); +}; + +#endif diff --git a/src/app/GUI/dirhistoryqueue.cpp b/src/app/GUI/dirhistoryqueue.cpp new file mode 100644 index 0000000..08c384e --- /dev/null +++ b/src/app/GUI/dirhistoryqueue.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + dirhistoryqueue.cpp - description + ------------------- + begin : Thu Jan 1 2004 + copyright : (C) 2004 by Shie Erlich & Rafi Yanai + email : +***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "dirhistoryqueue.h" +#include "../Panel/listpanel.h" + +#include <kdebug.h> + +DirHistoryQueue::DirHistoryQueue( ListPanel* p ) { + panel = p; + + connect( panel, TQ_SIGNAL( pathChanged( ListPanel* ) ), this, TQ_SLOT( slotPathChanged( ListPanel* ) ) ); +} +DirHistoryQueue::~DirHistoryQueue() {} + +/** No descriptions */ +void DirHistoryQueue::slotPathChanged( ListPanel* p ) { + KURL url = p->virtualPath(); + // already in the queue ? + if( urlQueue.findIndex( url ) >= 0 ){ + // remove it ! + urlQueue.remove( url ); + } + // do we have room for another ? + if ( urlQueue.size() > 12 ) { + // no room - remove the oldest entry + urlQueue.pop_back(); + } + + urlQueue.push_front( url ); +} + +#if 0 +void DirHistoryQueue::addUrl(const KURL& url){ + if ( pathQueue.findIndex( path ) == -1 ) { + if ( pathQueue.size() > 12 ) { + // remove the oldest entry + pathQueue.pop_back(); + } + } else { + pathQueue.remove( path ); + } + + pathQueue.push_front( path ); +} + +void DirHistoryQueue::RemovePath( const TQString& path ) { + TQStringList::iterator it; + it = pathQueue.find( path ); + if ( it != pathQueue.end() ) { + pathQueue.remove( it ); + } +} + +bool DirHistoryQueue::checkPath( const TQString& path ) { + KURL url( path ); + + TQString p = url.path(); + // kdDebug() << "url:" << p << ", file: " << url.fileName() << ", dir: " << url.directory() << endl; + if ( url.protocol() == "file" ) { + TQDir dir( path ); + if ( !dir.exists() ) { + RemovePath( path ); + return false; + } + } + + return true; + +} +#endif + +#include "dirhistoryqueue.moc" diff --git a/src/app/GUI/dirhistoryqueue.h b/src/app/GUI/dirhistoryqueue.h new file mode 100644 index 0000000..30a23a4 --- /dev/null +++ b/src/app/GUI/dirhistoryqueue.h @@ -0,0 +1,48 @@ +/*************************************************************************** + dirhistoryqueue.h - description + ------------------- + begin : Thu Jan 1 2004 + copyright : (C) 2004 by Shie Erlich & Rafi Yanai + email : + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 DIRHISTORYQUEUE_H +#define DIRHISTORYQUEUE_H + +#include <tqobject.h> +#include <kurl.h> + +class ListPanel; + +/** + *@author Shie Erlich & Rafi Yanai + */ + +class DirHistoryQueue : public TQObject { + TQ_OBJECT + +public: + DirHistoryQueue(ListPanel* p); + ~DirHistoryQueue(); + KURL::List urlQueue; +// bool checkPath(const TQString& path); +// void RemovePath(const TQString& path); + +public slots: // Public slots + /** No descriptions */ + void slotPathChanged(ListPanel* p); +private: +// void addUrl(const KURL& url); + ListPanel* panel; +}; + +#endif diff --git a/src/app/GUI/kcmdline.cpp b/src/app/GUI/kcmdline.cpp new file mode 100644 index 0000000..15ba45f --- /dev/null +++ b/src/app/GUI/kcmdline.cpp @@ -0,0 +1,253 @@ +/*************************************************************************** + kcmdline.cpp + ------------------- + copyright : (C) 2000 by Shie Erlich & Rafi Yanai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net +--------------------------------------------------------------------------- + Description +*************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + S o u r c e F i l e + +*************************************************************************** +* * +* 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. * +* * +***************************************************************************/ + + +#include "kcmdline.h" +#include "stdlib.h" +#include <unistd.h> +#include <tqmessagebox.h> +#include <kprocess.h> +#include <tqiconset.h> +#include <tqwhatsthis.h> +#include <unistd.h> +#include "../krusader.h" +#include "../kicons.h" +#include "../krslots.h" +#include "../resources.h" +#include "../defaults.h" +#include "../krusaderview.h" +#include "../Panel/listpanel.h" +#include "../krservices.h" +#include "../ActionMan/addplaceholderpopup.h" +#include "kcmdmodebutton.h" +#include <tqdir.h> +#include <kstandarddirs.h> +#include <tdelocale.h> +#include <tdeglobalsettings.h> +#include <tqfontmetrics.h> +#include <tqimage.h> +#include <tqstringlist.h> +#include <tqsizepolicy.h> +#include <tdetempfile.h> + +KCMDLine::KCMDLine( TQWidget *parent, const char *name ) : TQWidget( parent, name ) { + TQGridLayout * layout = new TQGridLayout( this, 1, 4 ); + path = new TQLabel( this ); + TQWhatsThis::add + ( path, i18n( "Name of directory where command will be processed." ) ); + path->setAlignment( TQt::AlignRight ); + path->setFrameStyle( TQFrame::Box | TQFrame::Sunken ); + path->setLineWidth( 1 ); + path->setFont( TDEGlobalSettings::generalFont() ); + int height = TQFontMetrics( TDEGlobalSettings::generalFont() ).height(); + height = height + 5*(height > 14) + 6; + path->setMaximumHeight( height ); + path->setSizePolicy(TQSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::Preferred)); + layout->addWidget( path, 0, 0 ); + + // and editable command line + completion.setMode( KURLCompletion::FileCompletion ); + cmdLine = new KrHistoryCombo( this ); + cmdLine->setMaxCount(100); // remember 100 commands + cmdLine->setDuplicatesEnabled( false ); + cmdLine->setFont( TDEGlobalSettings::generalFont() ); + cmdLine->setMaximumHeight( height ); + cmdLine->setCompletionObject( &completion ); + cmdLine->setSizePolicy(TQSizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Fixed)); + // load the history + TDEConfigGroupSaver grpSvr( krConfig, "Private" ); + TQStringList list = krConfig->readListEntry( "cmdline history" ); + cmdLine->setHistoryItems( list ); + + connect( cmdLine, TQ_SIGNAL( returnPressed(const TQString &) ), this, TQ_SLOT( slotRun() ) ); + connect( cmdLine, TQ_SIGNAL( returnPressed(const TQString &) ), cmdLine, TQ_SLOT( clearEdit() ) ); + connect( cmdLine, TQ_SIGNAL( returnToPanel() ), this, TQ_SLOT( slotReturnFocus() )); + + TQWhatsThis::add + ( cmdLine, i18n( "<qt><p>Well, it's actually quite simple: You type your command here and Krusader obeys.</p><p><b>Tip</b>: Move within command line history with <Up> and <Down> arrows.</p></qt>" ) ); + layout->addWidget( cmdLine, 0, 1 ); + + buttonAddPlaceholder = new TQToolButton( this, "ButtonAddPlaceholder" ); + buttonAddPlaceholder->setFixedSize(22,20); + buttonAddPlaceholder->adjustSize(); + buttonAddPlaceholder->setPixmap( SmallIcon( "add" ) ); + connect( buttonAddPlaceholder, TQ_SIGNAL( clicked() ), this, TQ_SLOT( addPlaceholder() ) ); + TQWhatsThis::add( buttonAddPlaceholder, i18n( "Add <b>Placeholders</b> for the selected files in the panel." ) ); + + layout->addWidget( buttonAddPlaceholder, 0, 2 ); + + // a run in terminal button + terminal = new KCMDModeButton( this ); + layout->addWidget( terminal, 0, 3 ); + + layout->activate(); +} + +void KCMDLine::addPlaceholder() { + AddPlaceholderPopup popup( this ); + TQString exp = popup.getPlaceholder( + buttonAddPlaceholder->mapToGlobal( TQPoint( 0, 0) ) + ); + this->addText( exp ); +} + +void KCMDLine::setCurrent( const TQString &p ) { + + TQString pathName = p; + TQFontMetrics fm(path->fontMetrics()); + int textWidth = fm.width(pathName); + int maxWidth = ( cmdLine->width() + path->width() ) * 2 / 5; + int letters = p.length() / 2; + + while ( letters && textWidth > maxWidth ) + { + pathName = p.left( letters ) + "..." + p.right( letters ); + letters--; + textWidth = fm.width(pathName); + } + + path->setText( pathName + ">" ); + + completion.setDir( p ); + // make sure our command is executed in the right directory + // This line is important for Krusader overall functions -> do not remove ! + chdir( p.local8Bit() ); +} + +KCMDLine::~KCMDLine() { + TDEConfigGroupSaver grpSvr( krConfig, "Private" ); + TQStringList list = cmdLine->historyItems(); + //krOut << list[0] << endl; + krConfig->writeEntry( "cmdline history", list ); + krConfig->sync(); +} + +void KCMDLine::slotRun() { + const TQString command1(cmdLine->currentText()); + if ( command1.isEmpty() ) + return ; + TQString panelPath = path->text().left( path->text().length() - 1 ); + + cmdLine->addToHistory(command1); + + if ( command1.simplifyWhiteSpace().left( 3 ) == "cd " ) { // cd command effect the active panel + TQString dir = command1.right( command1.length() - command1.find( " " ) ).stripWhiteSpace(); + if ( dir == "~" ) + dir = TQDir::homeDirPath(); + else + if ( dir.left( 1 ) != "/" && !dir.contains( ":/" ) ) + dir = panelPath + ( panelPath == "/" ? "" : "/" ) + dir; + SLOTS->refresh( dir ); + } else { + exec(); + cmdLine->clearEdit(); + } +} + + +void KCMDLine::slotReturnFocus() { + Krusader::App->mainView->cmdLineUnFocus(); +} + +static const KrActionBase::ExecType execModesMenu[] = { + KrActionBase::Normal, + KrActionBase::CollectOutputSeparateStderr, + KrActionBase::CollectOutput, + KrActionBase::Terminal, + KrActionBase::RunInTE, +}; + +TQString KCMDLine::command() const { + return cmdLine->currentText(); +} + +KrActionBase::ExecType KCMDLine::execType() const { + TDEConfigGroup grp( krConfig, "Private" ); + int i = grp.readNumEntry("Command Execution Mode",0); + return execModesMenu[i]; +} + +TQString KCMDLine::startpath() const { + return path->text().left( path->text().length() - 1 ); +} + +TQString KCMDLine::user() const { + return TQString(); +} + +TQString KCMDLine::text() const { + return cmdLine->currentText(); +} + +bool KCMDLine::acceptURLs() const { + return false; +} + +bool KCMDLine::confirmExecution() const { + return false; +} + +bool KCMDLine::doSubstitution() const { + return true; +} + +void KCMDLine::setText(TQString text) { + cmdLine->setCurrentText( text ); +} + +void KrHistoryCombo::keyPressEvent( TQKeyEvent *e ) { + switch (e->key()) { + case Key_Enter: + case Key_Return: + if (e->state() & ControlButton) { + SLOTS->insertFileName( ( e->state() & ShiftButton ) != 0 ); + break; + } + KHistoryCombo::keyPressEvent(e); + break; + case Key_Down: + if (e->state() == ( ControlButton | ShiftButton ) ) { + MAIN_VIEW->focusTerminalEmulator(); + return; + } else + KHistoryCombo::keyPressEvent(e); + break; + case Key_Up: + if (e->state() == ControlButton || e->state() == ( ControlButton | ShiftButton ) ) { + emit returnToPanel(); + return; + } + default: + KHistoryCombo::keyPressEvent(e); + } +} + +#include "kcmdline.moc" + diff --git a/src/app/GUI/kcmdline.h b/src/app/GUI/kcmdline.h new file mode 100644 index 0000000..be141c1 --- /dev/null +++ b/src/app/GUI/kcmdline.h @@ -0,0 +1,101 @@ +/*************************************************************************** + kcmdline.h + ------------------- + begin : Thu May 4 2000 + copyright : (C) 2000 by Shie Erlich & Rafi Yanai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net +--------------------------------------------------------------------------- + Description +*************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + H e a d e r F i l e + +*************************************************************************** +* * +* 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 KCMDLINE_H +#define KCMDLINE_H + +// TQt includes +#include <tqwidget.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqtoolbutton.h> + +// TDE includes +#include <klineedit.h> +#include <kshellcompletion.h> +#include <kcombobox.h> + +#include "../UserAction/kractionbase.h" + +class KCMDModeButton; + +class KrHistoryCombo: public KHistoryCombo { + TQ_OBJECT + + + public: + KrHistoryCombo(TQWidget *parent): KHistoryCombo(parent) {} + + protected: + void keyPressEvent( TQKeyEvent *e ); + + signals: + void returnToPanel(); +}; + +class KCMDLine : public TQWidget, KrActionBase { + TQ_OBJECT + + public: + KCMDLine( TQWidget *parent = 0, const char *name = 0 ); + ~KCMDLine(); + void setCurrent( const TQString & ); + //virtual methods from KrActionBase + void setText(TQString text); + TQString command() const; + ExecType execType() const; + TQString startpath() const; + TQString user() const; + TQString text() const; + bool acceptURLs() const; + bool confirmExecution() const; + bool doSubstitution() const; + signals: + void signalRun(); + public slots: + inline void setFocus() { cmdLine->setFocus(); } // overloaded for TDECmdLine + void slotReturnFocus(); // returns keyboard focus to panel + void slotRun(); + void addPlaceholder(); + void addText( TQString text ) { cmdLine->setCurrentText( cmdLine->currentText() + text ); } + void popup() { cmdLine->popup(); } + + + private: + TQLabel *path; + KrHistoryCombo *cmdLine; + KCMDModeButton *terminal; + TQToolButton *buttonAddPlaceholder; + KShellCompletion completion; +}; + +#endif diff --git a/src/app/GUI/kcmdmodebutton.cpp b/src/app/GUI/kcmdmodebutton.cpp new file mode 100644 index 0000000..b1e4a72 --- /dev/null +++ b/src/app/GUI/kcmdmodebutton.cpp @@ -0,0 +1,74 @@ +/*************************************************************************** + kcmmodebutton.cpp - description + ------------------- + + this file contains a class KCMDModeButton, which represents a button with + popup menu to switch the mode of the krusader built-in command-line + + begin : Oct 2006 + inspired by : other Krusader source files + author of this file : Vaclav Juza + email : vaclavjuza at gmail dot 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. * + * * + ***************************************************************************/ + +#include "kcmdmodebutton.h" + +#include "../krusader.h" +#include "../krusaderview.h" + +#include <tdeactionclasses.h> +#include <tdelocale.h> +#include <kiconloader.h> +#include <tdepopupmenu.h> + +#include <kdebug.h> + +KCMDModeButton::KCMDModeButton( TQWidget *parent, const char *name ) : TQToolButton( parent, name ) { + setFixedSize( 22, 20 ); +/* // from the old terminal-button: + setTextLabel( i18n( "If pressed, Krusader executes command line in a terminal." ) ); + TQWhatsThis::add( terminal, i18n( + "The 'run in terminal' button allows Krusader " + "to run console (or otherwise non-graphical) " + "programs in a terminal of your choice. If it's " + "pressed, terminal mode is active." ) ); +*/ + setIconSet( SmallIcon( "konsole" ) ); + adjustSize(); + action = new TDEActionMenu( i18n("Execution mode") ); + TQ_CHECK_PTR( action ); + for( int i=0; Krusader::execTypeArray[i] != 0; i++ ) + { + action->insert( *Krusader::execTypeArray[i] ); + } + TQPopupMenu *pP = action->popupMenu(); + TQ_CHECK_PTR( pP ); + setPopup( pP ); + setPopupDelay( 10 ); + setAcceptDrops( false ); +} + +KCMDModeButton::~KCMDModeButton() { + delete action; +} + +/** called when clicked to the button */ +void KCMDModeButton::openPopup() { + TQPopupMenu * pP = popup(); + if ( pP ) { + popup() ->exec( mapToGlobal( TQPoint( 0, 0 ) ) ); + } +} + + + +#include "kcmdmodebutton.moc" diff --git a/src/app/GUI/kcmdmodebutton.h b/src/app/GUI/kcmdmodebutton.h new file mode 100644 index 0000000..cb00290 --- /dev/null +++ b/src/app/GUI/kcmdmodebutton.h @@ -0,0 +1,53 @@ +/*************************************************************************** + kcmmodebutton.h - description + ------------------- + + this file contains a class KCMDModeButton, which represents a button with + popup menu to switch the mode of the krusader built-in command-line + + begin : Oct 2006 + inspired by : other Krusader source files + author of this file : Vaclav Juza + email : vaclavjuza at gmail dot 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. * + * * + ***************************************************************************/ + +#ifndef KCMDMODEBUTTON_H +#define KCMDMODEBUTTON_H + +#include <tqtoolbutton.h> + +class TDEActionMenu; + +/** + * @author Vaclav Juza + * + * represents a button for switching the command-line execution mode + * It extends TQToolButton, set the icon etc., and creates a popup menu + * containing the actions to actually switch the mode. + */ +class KCMDModeButton : public TQToolButton { + TQ_OBJECT + +public: + /** Constructor. Sets up the menu, and the icon */ + KCMDModeButton(TQWidget *parent=0, const char *name=0); + ~KCMDModeButton(); + + /** Shows the popup menu. Called when clicked to the button */ + void openPopup(); + +private: + /** The menu containing the actions for switching the mode */ + TDEActionMenu *action; +}; + +#endif diff --git a/src/app/GUI/kfnkeys.cpp b/src/app/GUI/kfnkeys.cpp new file mode 100644 index 0000000..1db34c6 --- /dev/null +++ b/src/app/GUI/kfnkeys.cpp @@ -0,0 +1,133 @@ +/*************************************************************************** + kfnkeys.cpp + ------------------- + copyright : (C) 2000 by Shie Erlich & Rafi Yanai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + S o u r c e F i l e + + *************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <tqtooltip.h> +#include <tdelocale.h> +#include <tdeglobalsettings.h> +#include <tqfontmetrics.h> +#include <tqwhatsthis.h> +#include "kfnkeys.h" +#include "../krusader.h" +#include "../defaults.h" +#include "../krslots.h" + +KFnKeys::KFnKeys(TQWidget *parent, char *name): TQWidget(parent,name) { + krConfig->setGroup("Look&Feel"); + //////////////////////////////// +#define SETUP(TARGET) {\ + TARGET->setMinimumWidth(45);\ +} + + setFont( TDEGlobalSettings::generalFont() ); + layout=new TQGridLayout(this,1,9); // 9 keys + F2=new TQPushButton( i18n("F2 Term ") ,this); + TQToolTip::add( F2, "<qt>" + i18n( "<p>Open terminal in current directory.</p>" + "<p>The terminal can be defined in Konfigurator, " + "default is <b>konsole</b>.</p>" ) + "</qt>" ); + connect(F2,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(terminal())); + SETUP(F2); + + F3=new TQPushButton( i18n("F3 View ") ,this); + TQToolTip::add( F3, i18n( "Open file in viewer." ) ); + connect(F3,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(view())); + SETUP(F3); + + F4=new TQPushButton( i18n("F4 Edit ") ,this); + TQToolTip::add( F4, "<qt>" + i18n( "<p>Edit file.</p>" + "<p>The editor can be defined in Konfigurator, " + "default is <b>internal editor</b>.</p>" ) + "</qt>" ); + connect(F4,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(edit())); + SETUP(F4); + + F5=new TQPushButton( i18n("F5 Copy ") ,this); + TQToolTip::add( F5, i18n( "Copy file from one panel to the other." ) ); + connect(F5,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(copyFiles())); + SETUP(F5); + + F6=new TQPushButton( i18n("F6 Move") ,this); + TQToolTip::add( F6, i18n( "Move file from one panel to the other." ) ); + connect(F6,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(moveFiles())); + SETUP(F6); + + F7=new TQPushButton( i18n("F7 Mkdir ") ,this); + TQToolTip::add( F7, i18n( "Create directory in current panel." ) ); + connect(F7,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(mkdir())); + SETUP(F7); + + F8=new TQPushButton( i18n("F8 Delete") ,this); + TQToolTip::add( F8, i18n( "Delete file, directory, etc." ) ); + connect(F8,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(deleteFiles())); + SETUP(F8); + + F9=new TQPushButton( i18n("F9 Rename") ,this); + TQToolTip::add( F9, i18n( "Rename file, directory, etc." ) ); + connect(F9,TQ_SIGNAL(clicked()), SLOTS, TQ_SLOT(rename())); + SETUP(F9); + + F10=new TQPushButton( i18n("F10 Quit ") ,this); + TQToolTip::add( F10, i18n( "Quit Krusader." ) ); + connect(F10,TQ_SIGNAL(clicked()),krApp, TQ_SLOT(slotClose())); + SETUP(F10); + + // set a tighter box around the keys + int h = TQFontMetrics(F2->font()).height()+2; + F2->setMaximumHeight(h); F3->setMaximumHeight(h); + F4->setMaximumHeight(h); F5->setMaximumHeight(h); + F6->setMaximumHeight(h); F7->setMaximumHeight(h); + F8->setMaximumHeight(h); F9->setMaximumHeight(h); + F10->setMaximumHeight(h); + + layout->addWidget(F2,0,0); + layout->addWidget(F3,0,1); + layout->addWidget(F4,0,2); + layout->addWidget(F5,0,3); + layout->addWidget(F6,0,4); + layout->addWidget(F7,0,5); + layout->addWidget(F8,0,6); + layout->addWidget(F9,0,7); + layout->addWidget(F10,0,8); + + layout->activate(); +} + +void KFnKeys::updateShortcuts() { + F2->setText(krF2->shortcut().toString() + i18n(" Term")); + F3->setText(krF3->shortcut().toString() + i18n(" View")); + F4->setText(krF4->shortcut().toString() + i18n(" Edit")); + F5->setText(krF5->shortcut().toString() + i18n(" Copy")); + F6->setText(krF6->shortcut().toString() + i18n(" Move")); + F7->setText(krF7->shortcut().toString() + i18n(" Mkdir")); + F8->setText(krF8->shortcut().toString() + i18n(" Delete")); + F9->setText(krF9->shortcut().toString() + i18n(" Rename")); + F10->setText(krF10->shortcut().toString() + i18n(" Quit")); +} + +#include "kfnkeys.moc" + diff --git a/src/app/GUI/kfnkeys.h b/src/app/GUI/kfnkeys.h new file mode 100644 index 0000000..86fc30c --- /dev/null +++ b/src/app/GUI/kfnkeys.h @@ -0,0 +1,55 @@ +/*************************************************************************** + kfnkeys.h + ------------------- + begin : Thu May 4 2000 + copyright : (C) 2000 by Shie Erlich & Rafi Yanai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + H e a d e r F i l e + + *************************************************************************** + * * + * 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 KFNKEYS_H +#define KFNKEYS_H + +#include <tqwidget.h> +#include <tqlayout.h> +#include <tqpushbutton.h> + +// Function Keys widget +/////////////////////// +class KFnKeys : public TQWidget { + TQ_OBJECT + + +public: + // constructor + KFnKeys(TQWidget *parent, char *name=0); + void updateShortcuts(); + +private: + TQPushButton *F2 ,*F3,*F4,*F5,*F6,*F7,*F8,*F9,*F10; + TQGridLayout *layout; +}; + +#endif diff --git a/src/app/GUI/krremoteencodingmenu.cpp b/src/app/GUI/krremoteencodingmenu.cpp new file mode 100644 index 0000000..2b9f19c --- /dev/null +++ b/src/app/GUI/krremoteencodingmenu.cpp @@ -0,0 +1,207 @@ +/*************************************************************************** + krremoteencodingmenu.cpp - description + ------------------- + copyright : (C) 2005 + by Csaba Karai + based on : KRemoteEncodingPlugin from Dawit Alemayehu + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + S o u r c e F i l e + + *************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <tdepopupmenu.h> +#include <kcharsets.h> +#include <tdeio/slaveconfig.h> +#include <dcopclient.h> + +#include "../krusader.h" +#include "../krusaderview.h" +#include "../Panel/listpanel.h" +#include "../Panel/panelfunc.h" + +#include "krremoteencodingmenu.h" + +#define DATA_KEY TQString::fromLatin1("Charset") + +KrRemoteEncodingMenu::KrRemoteEncodingMenu(const TQString &text, const TQString &icon, TQObject *parent, const char *name) : + TDEActionMenu( text, icon, parent, name ), settingsLoaded( false ) +{ + connect(popupMenu(), TQ_SIGNAL(aboutToShow()), this, TQ_SLOT(slotAboutToShow())); +} + +void KrRemoteEncodingMenu::slotAboutToShow() +{ + if (!settingsLoaded) + loadSettings(); + + // uncheck everything + for (unsigned i = 0; i < popupMenu()->count(); i++) + popupMenu()->setItemChecked(popupMenu()->idAt(i), false); + + KURL currentURL = ACTIVE_PANEL->virtualPath(); + + TQString charset = TDEIO::SlaveConfig::self()->configData(currentURL.protocol(), currentURL.host(), DATA_KEY); + if (!charset.isEmpty()) + { + int id = 1; + TQStringList::Iterator it; + for (it = encodingNames.begin(); it != encodingNames.end(); ++it, ++id) + if ((*it).find(charset) != -1) + break; + +// kdDebug() << k_funcinfo << "URL=" << currentURL << " charset=" << charset << endl; + + if (it == encodingNames.end()) + kdWarning() << k_funcinfo << "could not find entry for charset=" << charset << endl; + else + popupMenu()->setItemChecked(id, true); + } + else + popupMenu()->setItemChecked(defaultID, true); +} + +void KrRemoteEncodingMenu::loadSettings() +{ + settingsLoaded = true; + encodingNames = TDEGlobal::charsets()->descriptiveEncodingNames(); + + TDEPopupMenu *menu = popupMenu(); + menu->clear(); + + TQStringList::ConstIterator it; + int count = 0; + for (it = encodingNames.begin(); it != encodingNames.end(); ++it) + menu->insertItem(*it, this, TQ_SLOT(slotItemSelected(int)), 0, ++count); + menu->insertSeparator(); + + menu->insertItem(i18n("Reload"), this, TQ_SLOT(slotReload()), 0, ++count); + menu->insertItem(i18n("Default"), this, TQ_SLOT(slotDefault()), 0, ++count); + defaultID = count; +} + +int KrRemoteEncodingMenu::plug( TQWidget *widget, int index ) +{ + if( widget->inherits( "TQPopupMenu" ) ) + { + connect( widget, TQ_SIGNAL(aboutToShow()), this, TQ_SLOT(slotCheckEnabled())); + slotCheckEnabled(); + } + + return TDEActionMenu::plug( widget, index ); +} + +void KrRemoteEncodingMenu::slotCheckEnabled() +{ + KURL currentURL = ACTIVE_PANEL->virtualPath(); + setEnabled( currentURL.protocol() == "ftp" || currentURL.protocol() == "sftp" || currentURL.protocol() == "fish" ); +} + +void KrRemoteEncodingMenu::slotItemSelected(int id) +{ + KURL currentURL = ACTIVE_PANEL->virtualPath(); + + TDEConfig config(("tdeio_" + currentURL.protocol() + "rc").latin1()); + TQString host = currentURL.host(); + + if (!popupMenu()->isItemChecked(id)) + { + TQString charset = TDEGlobal::charsets()->encodingForName( encodingNames[id - 1] ); + + config.setGroup(host); + config.writeEntry(DATA_KEY, charset); + config.sync(); + + // Update the io-slaves... + updateKIOSlaves(); + } +} + +void KrRemoteEncodingMenu::slotReload() +{ + loadSettings(); +} + +void KrRemoteEncodingMenu::slotDefault() +{ + KURL currentURL = ACTIVE_PANEL->virtualPath(); + + // We have no choice but delete all higher domain level + // settings here since it affects what will be matched. + TDEConfig config(("tdeio_" + currentURL.protocol() + "rc").latin1()); + + TQStringList partList = TQStringList::split('.', currentURL.host(), false); + if (!partList.isEmpty()) + { + partList.remove(partList.begin()); + + TQStringList domains; + // Remove the exact name match... + domains << currentURL.host(); + + while (partList.count()) + { + if (partList.count() == 2) + if (partList[0].length() <= 2 && partList[1].length() == 2) + break; + + if (partList.count() == 1) + break; + + domains << partList.join("."); + partList.remove(partList.begin()); + } + + for (TQStringList::Iterator it = domains.begin(); it != domains.end(); it++) + { +// kdDebug() << k_funcinfo << "Domain to remove: " << *it << endl; + if (config.hasGroup(*it)) + config.deleteGroup(*it); + else if (config.hasKey(*it)) + config.deleteEntry(*it); + } + } + config.sync(); + + updateKIOSlaves(); +} + + +void KrRemoteEncodingMenu::updateKIOSlaves() +{ + // Inform running io-slaves about the change... + DCOPClient *client = new DCOPClient(); + + if (!client->attach()) + kdDebug() << "Can't connect with DCOP server." << endl; + + TQByteArray data; + TQDataStream stream(data, IO_WriteOnly); + stream << TQString(); + client->send("*", "TDEIO::Scheduler", "reparseSlaveConfiguration(TQString)", data); + delete client; + + // Reload the page with the new charset + TQTimer::singleShot( 500, ACTIVE_FUNC, TQ_SLOT( refresh() ) ); +} + +#include "krremoteencodingmenu.moc" diff --git a/src/app/GUI/krremoteencodingmenu.h b/src/app/GUI/krremoteencodingmenu.h new file mode 100644 index 0000000..254be82 --- /dev/null +++ b/src/app/GUI/krremoteencodingmenu.h @@ -0,0 +1,68 @@ +/*************************************************************************** + krremoteencodingmenu.h - description + ------------------- + copyright : (C) 2005 + by Csaba Karai + based on : KRemoteEncodingPlugin from Dawit Alemayehu + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + H e a d e r F i l e + + *************************************************************************** + * * + * 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 REMOTEENCODING_MENU_H +#define REMOTEENCODING_MENU_H + +#include <tqstringlist.h> +#include <kurl.h> +#include <klibloader.h> +#include <tdeaction.h> + +class KrRemoteEncodingMenu: public TDEActionMenu +{ + TQ_OBJECT + +public: + KrRemoteEncodingMenu (const TQString &text, const TQString &icon, TQObject *parent=0, const char *name=0); + + virtual int plug( TQWidget *widget, int index = -1); + +protected slots: + + void slotAboutToShow(); + void slotCheckEnabled(); + + void slotItemSelected(int); + void slotReload(); + void slotDefault(); + +private: + + void loadSettings(); + void updateKIOSlaves(); + + TQStringList encodingNames; + bool settingsLoaded; + int defaultID; +}; + +#endif /* REMOTEENCODING_MENU_H */ diff --git a/src/app/GUI/krusaderstatus.cpp b/src/app/GUI/krusaderstatus.cpp new file mode 100644 index 0000000..aa5f7f0 --- /dev/null +++ b/src/app/GUI/krusaderstatus.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + krusaderstatus.cpp + ------------------- + copyright : (C) 2000 by Shie Erlich & Rafi Yanai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + S o u r c e F i l e + + *************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// Krusader includes +#include <tqfontmetrics.h> +#include "krusaderstatus.h" +#include "../resources.h" + + +KrusaderStatus::KrusaderStatus(TQWidget *parent, const char *name ): + KStatusBar(parent,name){ + insertItem(i18n("Ready."), S_READY_ID); + setMaximumHeight(TQFontMetrics(font()).height()+2); +} + +KrusaderStatus::~KrusaderStatus(){ +} + +#include "krusaderstatus.moc" diff --git a/src/app/GUI/krusaderstatus.h b/src/app/GUI/krusaderstatus.h new file mode 100644 index 0000000..de8bec7 --- /dev/null +++ b/src/app/GUI/krusaderstatus.h @@ -0,0 +1,57 @@ +/*************************************************************************** + krusaderstatus.h + ------------------- + begin : Thu May 4 2000 + copyright : (C) 2000 by Shie Erlich & Rafi Yanai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + H e a d e r F i l e + + *************************************************************************** + * * + * 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 KRUSADERSTATUS_H +#define KRUSADERSTATUS_H + +// TQt includes +#include <tqlabel.h> +#include <tqwidget.h> +#include <tqframe.h> + +// TDE includes +#include <kstatusbar.h> +#include <tdelocale.h> + +class KrusaderStatus : public KStatusBar { + TQ_OBJECT + +public: + KrusaderStatus(TQWidget *parent=0, const char *name=0); + ~KrusaderStatus(); + +private: + TQLabel *mess; + +}; + +#endif diff --git a/src/app/GUI/mediabutton.cpp b/src/app/GUI/mediabutton.cpp new file mode 100644 index 0000000..c4cf6fd --- /dev/null +++ b/src/app/GUI/mediabutton.cpp @@ -0,0 +1,692 @@ +/*************************************************************************** + mediabutton.cpp - description + ------------------- + copyright : (C) 2006 + by Csaba Karai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + S o u r c e F i l e + + *************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "mediabutton.h" +#include "../krusader.h" +#include "../krservices.h" +#include "../kicons.h" +#include "../krslots.h" +#include "../MountMan/kdiskfreesp.h" +#include "../MountMan/kmountman.h" + +#include <tqpopupmenu.h> +#include <tqfile.h> +#include <tqfontmetrics.h> + +#include <tdelocale.h> +#include <kiconloader.h> + +#include <tdeversion.h> +#include <tdeio/job.h> +#include <tdemessagebox.h> +#include <kmimetype.h> +#include <kprotocolinfo.h> +#include <tdefileitem.h> +#include <kprocess.h> +#include <tqcursor.h> + +#ifdef Q_OS_LINUX +// For CD/DVD drive detection +#include <fcntl.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <stdint.h> +#define CDROM_GET_CAPABILITY 0x5331 +#define CDSL_CURRENT ((int) (~0U>>1)) +#define CDC_DVD_R 0x10000 /* drive can write DVD-R */ +#define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */ +#define CDC_CD_R 0x2000 /* drive is a CD-R */ +#define CDC_CD_RW 0x4000 /* drive is a CD-RW */ +#define CDC_DVD 0x8000 /* drive is a DVD */ +#include <tqfile.h> +#endif + + + +MediaButton::MediaButton( TQWidget *parent, const char *name ) : TQToolButton( parent, name ), + popupMenu( 0 ), rightMenu( 0 ), hasMedia( false ), waitingForMount( -1 ), mountCheckerTimer() + { + TDEIconLoader * iconLoader = new TDEIconLoader(); + TQPixmap icon = iconLoader->loadIcon( "blockdevice", TDEIcon::Toolbar, 16 ); + + setFixedSize( icon.width() + 4, icon.height() + 4 ); + setPixmap( icon ); + setTextLabel( i18n( "Open the available media list" ), true ); + setPopupDelay( 1 ); // immediate press + setAcceptDrops( false ); + + popupMenu = new TQPopupMenu( this ); + popupMenu->installEventFilter( this ); + TQ_CHECK_PTR( popupMenu ); + + setPopup( popupMenu ); + + connect( popupMenu, TQ_SIGNAL( aboutToShow() ), this, TQ_SLOT( slotAboutToShow() ) ); + connect( popupMenu, TQ_SIGNAL( aboutToHide() ), this, TQ_SLOT( slotAboutToHide() ) ); + connect( popupMenu, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( slotPopupActivated( int ) ) ); + + connect( &mountCheckerTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( slotTimeout() ) ); +} + +MediaButton::~MediaButton() { + busy = false; +} + +void MediaButton::slotAboutToShow() { + hasMedia = KProtocolInfo::isKnownProtocol( TQString( "media" ) ); + krConfig->setGroup( "Advanced" ); + if( krConfig->readBoolEntry( "DontUseMediaProt", !hasMedia ) ) + hasMedia = false; + + popupMenu->clear(); + urls.clear(); + mediaUrls.clear(); + mimes.clear(); + quasiMounted.clear(); + waitingForMount = -1; + + if( hasMedia ) + createListWithMedia(); + else + createListWithoutMedia(); + + mountCheckerTimer.start( 1000, true ); +} + +void MediaButton::slotAboutToHide() { + if( rightMenu ) + rightMenu->close(); + + if( waitingForMount < 0 ) + mountCheckerTimer.stop(); +} + +void MediaButton::createListWithMedia() { + TDEIO::ListJob *job = TDEIO::listDir( KURL( "media:/" ), false ); + connect( job, TQ_SIGNAL( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ), + this, TQ_SLOT( slotEntries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); + connect( job, TQ_SIGNAL( result( TDEIO::Job* ) ), + this, TQ_SLOT( slotListResult( TDEIO::Job* ) ) ); + busy = true; + + if( !busy ) + tqApp->processEvents(); +} + +void MediaButton::slotEntries( TDEIO::Job *, const TDEIO::UDSEntryList& entries ) +{ + KMountPoint::List mountList = KMountPoint::currentMountPoints(); + + TDEIO::UDSEntryListConstIterator it = entries.begin(); + TDEIO::UDSEntryListConstIterator end = entries.end(); + + while( it != end ) + { + KURL url; + TQString text; + TQString mime; + TQString localPath; + bool mounted = false; + + TDEIO::UDSEntry::ConstIterator it2 = (*it).begin(); + + for( ; it2 != (*it).end(); it2++ ) { + switch ((*it2).m_uds) { + case TDEIO::UDS_NAME: + text = KURL::decode_string((*it2).m_str); + break; + case TDEIO::UDS_URL: + url = KURL::fromPathOrURL( (*it2).m_str ); + break; + case TDEIO::UDS_MIME_TYPE: + mime = (*it2).m_str; + if( !mime.endsWith( "unmounted" ) ) + mounted = true; + break; +#if KDE_IS_VERSION(3,4,0) + case TDEIO::UDS_LOCAL_PATH: + localPath = (*it2).m_str; + break; +#endif + } + } + + if( text != "." && text != ".." ) { + int index = popupMenu->count(); + TQPixmap pixmap = FL_LOADICON( KMimeType::mimeType( mime ) ->icon( TQString(), true ) ); + + mediaUrls.append( url ); + + if( mounted && !localPath.isEmpty() ) + { + url = KURL::fromPathOrURL( localPath ); + if( !text.contains( url.path() ) ) + text += " [" + url.path() + "]"; + } + else if( mounted ) + { + url = getLocalPath( url, &mountList ); + if( url.isLocalFile() && !text.contains( url.path() ) ) + text += " [" + url.path() + "]"; + } + + popupMenu->insertItem( pixmap, text, index, index ); + + urls.append( url ); + mimes.append( mime ); + quasiMounted.append( false ); + } + ++it; + } +} + +void MediaButton::slotListResult( TDEIO::Job * ) { + busy = false; +} + +KURL MediaButton::getLocalPath( const KURL &url, KMountPoint::List *mountList ) { + KMountPoint::List mountListRef; + if( mountList == 0 ) { + mountListRef = KMountPoint::currentMountPoints(); + mountList = &mountListRef; + } + + for (KMountPoint::List::iterator it = mountList->begin(); it != mountList->end(); ++it) { + TQString name = (*it)->mountedFrom(); + name = name.mid( name.findRev( "/" ) + 1 ); + if( name == url.fileName() ) { + TQString point = (*it)->mountPoint(); + if( !point.isEmpty() ) + return KURL::fromPathOrURL( point ); + } + } + return url; +} + + +void MediaButton::createListWithoutMedia() { + /* WORKAROUND CODE START */ + + /* 1. the menu is drawn when we know all the mount points + 2. the menu is corrected, when the HDD volume sizes arrive from df + + when the volume sizes are added to the items, some cases widget resize + is necessary. If transparency is set for the widget, TQt produces weird + looking widgets, and that's why this workaround is used. + Here we add additional spaces to the mounted HDD elements for avoiding + the buggy widget resize. These are extra spaces. */ + + extraSpaces = ""; + TQFontMetrics fm( popupMenu->font() ); + int requiredWidth = fm.width( "999.9 GB " ); + while( fm.width( extraSpaces ) < requiredWidth ) + extraSpaces+=" "; + /* WORKAROUND CODE END */ + + KMountPoint::List possibleMountList = KMountPoint::possibleMountPoints(); + for (KMountPoint::List::iterator it = possibleMountList.begin(); it != possibleMountList.end(); ++it) { + addMountPoint( *it, false ); + } + + KMountPoint::List mountList = KMountPoint::currentMountPoints(); + for (KMountPoint::List::iterator it = mountList.begin(); it != mountList.end(); ++it) { + addMountPoint( *it, true ); + } +} + +TQString MediaButton::detectType( KMountPoint *mp ) +{ + TQString typeName = TQString(); +#ifdef Q_OS_LINUX + // Guessing device types by mount point is not exactly accurate... + // Do something accurate first, and fall back if necessary. + + bool isCd=false; + TQString devname=mp->mountedFrom().section('/', -1); + if(devname.startsWith("scd") || devname.startsWith("sr")) + { + // SCSI CD/DVD drive + isCd=true; + } + else if(devname.startsWith("hd")) + { + // IDE device -- we can't tell if this is a + // CD/DVD drive or harddisk by just looking at the + // filename + TQFile m(TQString("/proc/ide/") + devname + "/media"); + if(m.open(IO_ReadOnly)) + { + TQTextStream in(&m); + TQString buf=in.readLine(); + if(buf.contains("cdrom")) + isCd=true; + m.close(); + } + } + if(isCd) + { + int device=::open((const char *)TQFile::encodeName(mp->mountedFrom()), O_RDONLY | O_NONBLOCK ); + if(device>=0) + { + int drv=::ioctl(device, CDROM_GET_CAPABILITY, CDSL_CURRENT); + if(drv>=0) + { + if((drv & CDC_DVD_R) || (drv & CDC_DVD_RAM)) + typeName = "dvdwriter"; + else if((drv & CDC_CD_R) || (drv & CDC_CD_RW)) + typeName = "cdwriter"; + else if(drv & CDC_DVD) + typeName = "dvd"; + else + typeName = "cdrom"; + } + + ::close(device); + } + } + if( !typeName.isNull() ) + return typeName; + +#elif defined(__FreeBSD__) + if (-1!=mp->mountedFrom().find("/acd",0,false)) typeName="cdrom"; + else if (-1!=mp->mountedFrom().find("/scd",0,false)) typeName="cdrom"; + else if (-1!=mp->mountedFrom().find("/ad",0,false)) typeName="hdd"; + else if (-1!=mp->mountedFrom().find("/da",0,false)) typeName="hdd"; + else if (-1!=mp->mountedFrom().find("/afd",0,false)) typeName="zip"; + else +#endif + + /* Guessing of cdrom and cd recorder devices */ + if (-1!=mp->mountPoint().find("cdrom",0,false)) typeName="cdrom"; + else if (-1!=mp->mountedFrom().find("cdrom",0,false)) typeName="cdrom"; + else if (-1!=mp->mountPoint().find("cdwriter",0,false)) typeName="cdwriter"; + else if (-1!=mp->mountedFrom().find("cdwriter",0,false)) typeName="cdwriter"; + else if (-1!=mp->mountedFrom().find("cdrw",0,false)) typeName="cdwriter"; + else if (-1!=mp->mountPoint().find("cdrw",0,false)) typeName="cdwriter"; + else if (-1!=mp->mountedFrom().find("cdrecorder",0,false)) typeName="cdwriter"; + else if (-1!=mp->mountPoint().find("cdrecorder",0,false)) typeName="cdwriter"; + else if (-1!=mp->mountedFrom().find("dvdrecorder",0,false)) typeName="dvdwriter"; + else if (-1!=mp->mountPoint().find("dvdrecorder",0,false)) typeName="dvdwriter"; + else if (-1!=mp->mountPoint().find("dvdwriter",0,false)) typeName="dvdwriter"; + else if (-1!=mp->mountedFrom().find("dvdwriter",0,false)) typeName="dvdwriter"; + else if (-1!=mp->mountPoint().find("dvd",0,false)) typeName="dvd"; + else if (-1!=mp->mountedFrom().find("dvd",0,false)) typeName="dvd"; + else if (-1!=mp->mountedFrom().find("/dev/scd",0,false)) typeName="cdrom"; + else if (-1!=mp->mountedFrom().find("/dev/sr",0,false)) typeName="cdrom"; + + /* Guessing of floppy types */ + else if (-1!=mp->mountedFrom().find("fd",0,false)) { + if (-1!=mp->mountedFrom().find("360",0,false)) typeName="floppy5"; + if (-1!=mp->mountedFrom().find("1200",0,false)) typeName="floppy5"; + else typeName="floppy"; + } + else if (-1!=mp->mountPoint().find("floppy",0,false)) typeName="floppy"; + + else if (-1!=mp->mountPoint().find("zip",0,false)) typeName="zip"; + else if (-1!=mp->mountType().find("nfs",0,false)) typeName="nfs"; + else if (-1!=mp->mountType().find("smb",0,false)) typeName="smb"; + else if (-1!=mp->mountedFrom().find("//",0,false)) typeName="smb"; + else typeName="hdd"; + + return typeName; +} + +void MediaButton::slotPopupActivated( int elem ) { + if( !quasiMounted[ elem ] && mimes[ elem ].endsWith( "_unmounted" ) ) { + mount( elem ); + waitingForMount = elem; + maxMountWait = 20; + newTabAfterMount = false; + mountCheckerTimer.start( 1000, true ); + return; + } + emit openUrl( urls[ elem ] ); +} + +void MediaButton::gettingSpaceData(const TQString &mountPoint, unsigned long kBSize, unsigned long, unsigned long ) { + KURL mediaURL = KURL::fromPathOrURL( mountPoint ); + + TDEIO::filesize_t size = kBSize; + size *= 1024; + TQString sizeText = TDEIO::convertSize( size ); + + for( unsigned i=0; i != urls.size(); i++ ) { + if( mediaURL.equals( urls[ i ], true ) ) { + if( kBSize == 0 ) { // if df gives 0, it means the device is quasy umounted + TQString mime = mimes[ i ]; + if( mimes[ i ].endsWith( "_mounted" ) ) { + quasiMounted[ i ] = true; + mimes[ i ] = mimes[ i ].replace( "_mounted", "_unmounted" ); + } + + TQPixmap pixmap = FL_LOADICON( KMimeType::mimeType( mimes[ i ] ) ->icon( TQString(), true ) ); + popupMenu->changeItem( i, pixmap, popupMenu->text( i ) ); + } + else if( mimes[ i ].contains( "hdd_" ) ) + popupMenu->changeItem( i, sizeText + " " + popupMenu->text( i ).stripWhiteSpace() ); + return; + } + } +} + +void MediaButton::openPopup() { + TQPopupMenu * pP = popup(); + if ( pP ) { + popup() ->exec( mapToGlobal( TQPoint( 0, height() ) ) ); + } +} + +void MediaButton::addMountPoint( KMountPoint * mp, bool isMounted ) { + TQString mountString = isMounted ? "_mounted" : "_unmounted"; + if( mp->mountPoint() == "/dev/swap" || + mp->mountPoint() == "/dev/pts" || + mp->mountPoint().startsWith( "/sys/kernel" ) || + mp->mountPoint().find( "/proc" ) == 0 ) + return; + if( mp->mountType() == "swap" || + mp->mountType() == "sysfs" || + mp->mountType() == "tmpfs" || + mp->mountType() == "kernfs" || + mp->mountType() == "usbfs" || + mp->mountType() == "unknown" || + mp->mountType() == "none" || + mp->mountType() == "sunrpc" ) + return; + if( mp->mountedFrom() == "none" || + mp->mountedFrom() == "tmpfs" || + mp->mountedFrom().find( "shm" ) != -1 ) + return; + + int overwrite = -1; + KURL mountURL = KURL::fromPathOrURL( mp->mountPoint() ); + + for( unsigned i=0; i != urls.size(); i++ ) + if( urls[ i ].equals( mountURL, true ) ) { + overwrite = i; + break; + } + + TQString name; + TQString type = detectType( mp ); + + /* WORKAROUND CODE START */ + /* add spaces to avoid widget resize in gettingSpaceData, + which is buggy in TQt when transparency is set */ + TQString extSpc = ( isMounted && type == "hdd" ) ? extraSpaces : ""; + /* WORKAROUND CODE END */ + +#if KDE_IS_VERSION(3,4,0) + TQString mimeBase = "media/"; +#else + TQString mimeBase = "kdedevice/"; +#endif + + TQString mime = mimeBase + type + mountString; + + if( type == "hdd" ) + name = i18n( "Hard Disk" ) ; + else if( type == "cdrom" ) + name = i18n( "CD-ROM" ); + else if( type == "cdwriter" ) + name = i18n( "CD Recorder" ); + else if( type == "dvdwriter" ) { + mime = mimeBase + "cdwriter" + mountString; + name = i18n( "DVD Recorder" ); + } + else if( type == "dvd" ) + name = i18n( "DVD" ); + else if( type == "smb" ) + name = i18n( "Remote Share" ); + else if( type == "nfs" ) + name = i18n( "Remote Share" ); + else if( type == "floppy" ) + name = i18n( "Floppy" ); + else if( type == "floppy5" ) + name = i18n( "Floppy" ); + else if( type == "zip" ) + name = i18n( "Zip Disk" ); + else { + mime = mimeBase + "hdd" + mountString; + name = i18n( "Unknown" ); + } + + if( isMounted ) { + KDiskFreeSp *sp = KDiskFreeSp::findUsageInfo( mp->mountPoint() ); + connect( sp, TQ_SIGNAL( foundMountPoint( const TQString &, unsigned long, unsigned long, unsigned long ) ), + this, TQ_SLOT( gettingSpaceData( const TQString&, unsigned long, unsigned long, unsigned long ) ) ); + } + + TQPixmap pixmap = FL_LOADICON( KMimeType::mimeType( mime ) ->icon( TQString(), true ) ); + + if( overwrite == -1 ) { + int index = popupMenu->count(); + urls.append( KURL::fromPathOrURL( mp->mountPoint() ) ); + mimes.append( mime ); + mediaUrls.append( KURL() ); + quasiMounted.append( false ); + popupMenu->insertItem( pixmap, name + " [" + mp->mountPoint() + "]" + extSpc, index, index ); + } + else { + mimes[ overwrite ] = mime; + popupMenu->changeItem( overwrite, pixmap, name + " [" + mp->mountPoint() + "]" + extSpc ); + } +} + +bool MediaButton::eventFilter( TQObject *o, TQEvent *e ) { + if( o == popupMenu ) { + if( e->type() == TQEvent::MouseButtonPress || e->type() == TQEvent::MouseButtonRelease ) { + TQMouseEvent *m = static_cast<TQMouseEvent*>(e); + if( m->button() == TQt::RightButton ) { + if( e->type() == TQEvent::MouseButtonPress ) { + int id = popupMenu->idAt( m->pos() ); + if( id != -1 ) + rightClickMenu( id ); + } + m->accept(); + return true; + } + } + } + return false; +} + +void MediaButton::rightClickMenu( int index ) { + if( rightMenu ) + rightMenu->close(); + + TQString mime = mimes[ index ]; + bool ejectable = mime.contains( "dvd_" ) || mime.contains( "dvdwriter_" ) || mime.contains( "cdrom_" ) || mime.contains( "cdwriter_" ); + bool mounted = mime.contains( "_mounted" ); + + TQPopupMenu * myMenu = rightMenu = new TQPopupMenu( popupMenu ); + myMenu->insertItem( i18n( "Open" ), 1 ); + myMenu->insertItem( i18n( "Open in a new tab" ), 2 ); + myMenu->insertSeparator(); + if( !mounted ) + myMenu->insertItem( i18n( "Mount" ), 3 ); + else + myMenu->insertItem( i18n( "Unmount" ), 4 ); + if( ejectable ) + myMenu->insertItem( i18n( "Eject" ), 5 ); + int result = myMenu->exec( TQCursor::pos() ); + delete myMenu; + if( rightMenu == myMenu ) + rightMenu = 0; + else + return; + + switch ( result ) { + case 1: + case 2: + popupMenu->close(); + if( mounted || quasiMounted[ index ] ) { + if( result == 1 ) + emit openUrl( urls[ index ] ); + else + SLOTS->newTab( urls[ index ] ); + } else { + mount( index ); // mount first, when mounted open the tab + waitingForMount = index; + maxMountWait = 20; + newTabAfterMount = ( result == 2 ); + mountCheckerTimer.start( 1000, true ); + } + break; + case 3: + mount( index ); + break; + case 4: + umount( index ); + break; + case 5: + eject( index ); + break; + default: + break; + } +} + +bool MediaButton::mount( int index ) { + if ( (unsigned)index < mimes.count() ) { + if( !mediaUrls[ index ].isEmpty() ) { + TDEProcess proc; + proc << KrServices::fullPathName( "tdeio_media_mounthelper" ) << "-m" << mediaUrls[ index ].url(); + proc.start( TDEProcess::DontCare ); + } else { + krMtMan.mount( urls[ index ].path(), false ); + } + } + return false; +} + +bool MediaButton::umount( int index ) { + if ( (unsigned)index < mimes.count() ) { + if( !mediaUrls[ index ].isEmpty() ) { + TDEProcess proc; + proc << KrServices::fullPathName( "tdeio_media_mounthelper" ) << "-u" << mediaUrls[ index ].url(); + proc.start( TDEProcess::DontCare ); + } else { + krMtMan.unmount( urls[ index ].path(), false ); + } + } + return false; +} + +bool MediaButton::eject( int index ) { + if ( (unsigned)index < mimes.count() ) { + if( !mediaUrls[ index ].isEmpty() ) { + TDEProcess proc; + proc << KrServices::fullPathName( "tdeio_media_mounthelper" ) << "-e" << mediaUrls[ index ].url(); + proc.start( TDEProcess::DontCare ); + } else { + krMtMan.eject( urls[ index ].path() ); + } + } + return false; +} + +void MediaButton::slotTimeout() { + if( isHidden() && ( waitingForMount < 0 ) ) + return; + + KMountPoint::List mountList = KMountPoint::currentMountPoints(); + + for( unsigned index = 0; index < urls.count(); index++ ) { + bool mounted = false; + + TQString text = popupMenu->text( index ); + + if( mediaUrls[ index ].isEmpty() ) { + for (KMountPoint::List::iterator it = mountList.begin(); it != mountList.end(); ++it) + if( (*it)->mountPoint() == urls[ index ].path() ) { + mounted = true;; + break; + } + } else { + KURL uri = getLocalPath( mediaUrls[ index ], &mountList ); + if( uri.isLocalFile() ) { + urls[ index ] = uri; + mounted = true; + + if( !text.contains( uri.path() ) ) + { + if( text.endsWith( "]" ) ) + { + int ndx = text.findRev( " [" ); + if( ndx >0 ) + text.truncate( ndx ); + } + + text += " [" + uri.path() + "]"; + } + } + else + { + if( text.endsWith( "]" ) ) + { + int ndx = text.findRev( " [" ); + if( ndx >0 ) + text.truncate( ndx ); + } + } + } + + if( quasiMounted[ index ] ) // mounted but not listed with DF + mounted = false; + + if( mimes[ index ].contains( "_mounted" ) && !mounted ) + mimes[ index ] = mimes[ index ].replace( "_mounted", "_unmounted" ); + if( mimes[ index ].contains( "_unmounted" ) && mounted ) + mimes[ index ] = mimes[ index ].replace( "_unmounted", "_mounted" ); + + TQPixmap pixmap = FL_LOADICON( KMimeType::mimeType( mimes[ index ] ) ->icon( TQString(), true ) ); + popupMenu->changeItem( index, pixmap, text ); + + if( ((int)index == waitingForMount) && mounted ) { + waitingForMount = -1; + if( newTabAfterMount ) + SLOTS->newTab( urls[ index ] ); + else + emit openUrl( urls[ index ] ); + } + } + + if( waitingForMount >= 0 ) { // maximum wait for mounting expired ? + if( --maxMountWait < 0 ) { + waitingForMount = -1; + return; + } + } + + mountCheckerTimer.start( 1000, true ); +} + + +#include "mediabutton.moc" diff --git a/src/app/GUI/mediabutton.h b/src/app/GUI/mediabutton.h new file mode 100644 index 0000000..c416913 --- /dev/null +++ b/src/app/GUI/mediabutton.h @@ -0,0 +1,107 @@ +/*************************************************************************** + mediabutton.h - description + ------------------- + copyright : (C) 2006 + by Csaba Karai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + H e a d e r F i l e + + *************************************************************************** + * * + * 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 MEDIABUTTON_H +#define MEDIABUTTON_H + +#include <tqwidget.h> +#include <tqtoolbutton.h> +#include <kurl.h> +#include <tdeio/jobclasses.h> +#include <tqvaluelist.h> +#include <kmountpoint.h> +#include <tqtimer.h> + +/** + *@author Csaba Karai + */ + +class TQPopupMenu; +class KMountPoint; + +class MediaButton : public TQToolButton { + TQ_OBJECT + +public: + MediaButton(TQWidget *parent=0, const char *name=0); + ~MediaButton(); + + TQString detectType( KMountPoint *mp ); + +public slots: + void slotAboutToShow(); + void slotAboutToHide(); + void slotTimeout(); + void slotPopupActivated( int ); + void gettingSpaceData(const TQString &mountPoint, unsigned long kBSize, unsigned long kBUsed, unsigned long kBAvail); + void openPopup(); + void slotEntries( TDEIO::Job*, const TDEIO::UDSEntryList& ); + void slotListResult( TDEIO::Job* ); + +signals: + void openUrl(const KURL&); + +protected: + bool eventFilter( TQObject *o, TQEvent *e ); + +private: + void createListWithMedia(); + void createListWithoutMedia(); + + KURL getLocalPath( const KURL &, KMountPoint::List * list = 0 ); + bool mount( int ); + bool umount( int ); + bool eject( int ); + + void rightClickMenu( int ); + + void addMountPoint( KMountPoint *mp, bool isMounted ); + + TQPopupMenu *popupMenu; + TQPopupMenu *rightMenu; + + bool hasMedia; + bool busy; + + int waitingForMount; + bool newTabAfterMount; + int maxMountWait; + + TQValueList<KURL> urls; + TQValueList<KURL> mediaUrls; + TQValueList<TQString> mimes; + TQValueList<bool> quasiMounted; + + TQString extraSpaces; //prevents from increasing the size of the widget + + TQTimer mountCheckerTimer; +}; + +#endif /* MEDIABUTTON_H */ diff --git a/src/app/GUI/profilemanager.cpp b/src/app/GUI/profilemanager.cpp new file mode 100644 index 0000000..8805845 --- /dev/null +++ b/src/app/GUI/profilemanager.cpp @@ -0,0 +1,198 @@ +/*************************************************************************** + profilemanager.cpp - description + ------------------- + copyright : (C) 2004 + by Csaba Karai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + S o u r c e F i l e + + *************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "../krusader.h" +#include "profilemanager.h" + +#include <tdelocale.h> +#include <tqtooltip.h> +#include <tdepopupmenu.h> +#include <tqcursor.h> +#include <kinputdialog.h> +#include <kiconloader.h> + +ProfileManager::ProfileManager( TQString profileType, TQWidget * parent, const char * name ) + : TQPushButton( parent, name ) +{ + setText( "" ); + TDEIconLoader *iconLoader = new TDEIconLoader(); + setPixmap( iconLoader->loadIcon( "kr_profile", TDEIcon::Toolbar, 16 ) ); + TQToolTip::add( this, i18n( "Profiles" ) ); + + this->profileType = profileType; + + connect( this, TQ_SIGNAL( clicked() ), this, TQ_SLOT( profilePopup() ) ); + + krConfig->setGroup("Private"); + profileList = krConfig->readListEntry( profileType ); +} + +void ProfileManager::profilePopup() +{ + // profile menu identifiers + #define ADD_NEW_ENTRY_ID 1000 + #define LOAD_ENTRY_ID 2000 + #define REMOVE_ENTRY_ID 3000 + #define OVERWRITE_ENTRY_ID 4000 + + // create the menu + TDEPopupMenu popup, removePopup, overwritePopup; + popup.insertTitle(i18n("Profiles")); + + for( unsigned i=0; i != profileList.count() ; i++ ) + { + krConfig->setGroup( profileType + " - " + profileList[i] ); + TQString name = krConfig->readEntry( "Name" ); + popup.insertItem( name, LOAD_ENTRY_ID + i ); + removePopup.insertItem( name, REMOVE_ENTRY_ID + i ); + overwritePopup.insertItem( name, OVERWRITE_ENTRY_ID + i ); + } + + popup.insertSeparator(); + + if( profileList.count() ) + { + popup.insertItem( i18n("Remove entry"), &removePopup ); + popup.insertItem( i18n("Overwrite entry"), &overwritePopup ); + } + + popup.insertItem(i18n("Add new entry"),ADD_NEW_ENTRY_ID); + + unsigned result=popup.exec(TQCursor::pos()); + + // check out the user's selection + if( result == ADD_NEW_ENTRY_ID ) + newProfile(); + else if( result >= LOAD_ENTRY_ID && result < LOAD_ENTRY_ID + profileList.count() ) + { + emit loadFromProfile( profileType + " - " + profileList[ result - LOAD_ENTRY_ID ] ); + }else if( result >= REMOVE_ENTRY_ID && result < REMOVE_ENTRY_ID + profileList.count() ) + { + krConfig->deleteGroup( profileType + " - " + profileList[ result - REMOVE_ENTRY_ID ] ); + profileList.remove( profileList[ result - REMOVE_ENTRY_ID ] ); + + krConfig->setGroup("Private"); + krConfig->writeEntry( profileType, profileList ); + krConfig->sync(); + }else if( result >= OVERWRITE_ENTRY_ID && result < OVERWRITE_ENTRY_ID + profileList.count() ) + { + emit saveToProfile( profileType + " - " + profileList[ result - OVERWRITE_ENTRY_ID ] ); + } +} + +void ProfileManager::newProfile( TQString defaultName ) +{ + TQString profile = KInputDialog::getText( i18n( "Krusader::ProfileManager" ), i18n( "Enter the profile name:" ), + defaultName, 0, this ); + if( !profile.isEmpty() ) + { + int profileNum = 1; + while( profileList.contains( TQString( "%1" ).arg( profileNum ) ) ) + profileNum++; + + TQString profileString = TQString( "%1" ).arg( profileNum ); + TQString profileName = profileType + " - " + profileString; + profileList.append( TQString( "%1" ).arg( profileString ) ); + + krConfig->setGroup("Private"); + krConfig->writeEntry( profileType, profileList ); + + krConfig->setGroup( profileName ); + krConfig->writeEntry( "Name", profile ); + emit saveToProfile( profileName ); + krConfig->sync(); + } +} + +void ProfileManager::deleteProfile( TQString name ) +{ + for( unsigned i=0; i != profileList.count() ; i++ ) + { + krConfig->setGroup( profileType + " - " + profileList[ i ] ); + TQString currentName = krConfig->readEntry( "Name" ); + + if( name == currentName ) + { + krConfig->deleteGroup( profileType + " - " + profileList[ i ] ); + profileList.remove( profileList[ i ] ); + + krConfig->setGroup("Private"); + krConfig->writeEntry( profileType, profileList ); + krConfig->sync(); + return; + } + } +} + +void ProfileManager::overwriteProfile( TQString name ) +{ + for( unsigned i=0; i != profileList.count() ; i++ ) + { + krConfig->setGroup( profileType + " - " + profileList[ i ] ); + TQString currentName = krConfig->readEntry( "Name" ); + + if( name == currentName ) + { + emit saveToProfile( profileType + " - " + profileList[ i ] ); + return; + } + } +} + +bool ProfileManager::loadProfile( TQString name ) +{ + for( unsigned i=0; i != profileList.count() ; i++ ) + { + krConfig->setGroup( profileType + " - " + profileList[i] ); + TQString currentName = krConfig->readEntry( "Name" ); + + if( name == currentName ) + { + emit loadFromProfile( profileType + " - " + profileList[ i ] ); + return true; + } + } + return false; +} + +TQStringList ProfileManager::availableProfiles( TQString profileType ) { + krConfig->setGroup("Private"); + TQStringList profiles = krConfig->readListEntry( profileType ); + TQStringList profileNames; + + for( unsigned i=0; i != profiles.count() ; i++ ) { + krConfig->setGroup( profileType + " - " + profiles[ i ] ); + profileNames.append( krConfig->readEntry("Name") ); + } + + return profileNames; +} + +#include "profilemanager.moc" diff --git a/src/app/GUI/profilemanager.h b/src/app/GUI/profilemanager.h new file mode 100644 index 0000000..9fb244e --- /dev/null +++ b/src/app/GUI/profilemanager.h @@ -0,0 +1,70 @@ +/*************************************************************************** + profilemanager.h - description + ------------------- + copyright : (C) 2004 + by Csaba Karai + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** + + A + + db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b. + 88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D + 88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY' + 88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b + 88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88. + YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD + + H e a d e r F i l e + + *************************************************************************** + * * + * 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 PROFILEMANAGER_H +#define PROFILEMANAGER_H + +#include <tqpushbutton.h> +#include <tqstring.h> + +class ProfileManager : public TQPushButton +{ + TQ_OBJECT + + +public: + ProfileManager( TQString profileType, TQWidget * parent = 0, const char * name = 0 ); + + /** + * @param profileType Type of the profile (sync, search, ...) + * @return A list of all available profile-names + */ + static TQStringList availableProfiles( TQString profileType ); + + TQStringList getNames(); + +public slots: + void profilePopup(); + + void newProfile( TQString defaultName = TQString() ); + void deleteProfile( TQString name ); + void overwriteProfile( TQString name ); + bool loadProfile( TQString name ); + +signals: + void saveToProfile( TQString profileName ); + void loadFromProfile( TQString profileName ); + +private: + TQString profileType; + TQStringList profileList; +}; + +#endif /* PROFILEMANAGER_H */ diff --git a/src/app/GUI/syncbrowsebutton.cpp b/src/app/GUI/syncbrowsebutton.cpp new file mode 100644 index 0000000..1c4bde8 --- /dev/null +++ b/src/app/GUI/syncbrowsebutton.cpp @@ -0,0 +1,72 @@ +/*************************************************************************** + syncbrowsebutton.h - description + ------------------- + copyright : (C) 2004 by Jonas Bähr + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** +This is the button which toggles the synchron-browse-mode (a directory-change +is done in both panels) +I could imagine an optional extension which also performs mkdir etc. in the other panel +or in ALL tabs on the other side (this could also include copy-actions to this panels) +This is very handy if you have several identical clients which you want to update +simoultanious. + +The current version only manages sync-browse and got no mode-switch options. + + *************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "syncbrowsebutton.h" + +#include <tdelocale.h> +#include <kiconloader.h> + +//#include <kdebug.h> + +SyncBrowseButton::SyncBrowseButton(TQWidget *parent, const char *name) : TQToolButton(parent,name) +{ + TDEIconLoader *iconLoader = new TDEIconLoader(); + _icon_on = iconLoader->loadIcon( "kr_syncbrowse_on", TDEIcon::Toolbar, 16 ); + _icon_off = iconLoader->loadIcon( "kr_syncbrowse_off", TDEIcon::Toolbar, 16 ); + + setFixedSize( _icon_off.width() + 4, _icon_off.height() + 4 ); + setPixmap( _icon_off ); + setToggleButton( true ); + + setTextLabel( i18n( "This button toggles the sync-browse mode.\n" + "When active, each directory change is performed in the\n" + "active and inactive panel - if possible." ), true ); //set this as toop-tip (somehow whatsthis::add(this, ...) don't work) + + connect( this, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(slotToggled(bool)) ); +} + +SyncBrowseButton::~SyncBrowseButton() { +} + +void SyncBrowseButton::slotToggled( bool on ) { + if ( on ) + setPixmap( _icon_on ); + else + setPixmap( _icon_off ); +} + +int SyncBrowseButton::state() { + if ( isOn() ) + _state = SYNCBROWSE_CD; + else + _state = SYNCBROWSE_OFF; + + return _state; +} + + +#include "syncbrowsebutton.moc" diff --git a/src/app/GUI/syncbrowsebutton.h b/src/app/GUI/syncbrowsebutton.h new file mode 100644 index 0000000..75e8ed8 --- /dev/null +++ b/src/app/GUI/syncbrowsebutton.h @@ -0,0 +1,67 @@ +/*************************************************************************** + syncbrowsebutton.h - description + ------------------- + copyright : (C) 2004 by Jonas Bähr + e-mail : krusader@users.sourceforge.net + web site : http://krusader.sourceforge.net + --------------------------------------------------------------------------- + Description + *************************************************************************** +This is the button which toggles the synchron-browse-mode (a directory-change +is done in both panels) +I could imagine an optional extension which also performs mkdir etc. in the other panel +or in ALL tabs on the other side (this could also include copy-actions to this panels) +This is very handy if you have several identical clients which you want to update +simoultanious. + +The current version only manages sync-browse and got no mode-switch options. + + *************************************************************************** + * * + * 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 SYNCBROWSEBUTTON_H +#define SYNCBROWSEBUTTON_H + +#include <tqtoolbutton.h> + +// No synchrone browsing +#define SYNCBROWSE_OFF 0 +// Change only the directory +#define SYNCBROWSE_CD 1 +/* +// Make new dirs in both panels +#define SYNCBROWSE_MKDIR 2 +// Delete in both panels +#define SYNCBROWSE_DELETE 4 + +// Do everything in all tabs on the other side (not only the oposite panel) +#define SYNCBROWSE_ALLTABS 1024 +// Copy files not only to the other panel but to all tabs on the other side +#define SYNCBROWSE_COPY 2048 +*/ + +class SyncBrowseButton : public TQToolButton { + TQ_OBJECT + +public: + SyncBrowseButton(TQWidget *parent=0, const char *name=0); + ~SyncBrowseButton(); + + int state(); + +protected: + int _state; + TQPixmap _icon_on; + TQPixmap _icon_off; + +private slots: + void slotToggled(bool on); +}; + +#endif |