From 71abba5631126445560d6ab309a51c28745a0b74 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 15 Feb 2013 23:21:33 -0600 Subject: Fix prior commit --- tdeio/tdefile/kdiroperator.cpp | 1740 ------------------------------------ tdeio/tdefile/kdiroperator.h | 950 -------------------- tdeio/tdefile/tdediroperator.cpp | 1740 ++++++++++++++++++++++++++++++++++++ tdeio/tdefile/tdediroperator.h | 950 ++++++++++++++++++++ tdeio/tdeio/kemailsettings.cpp | 272 ------ tdeio/tdeio/kemailsettings.h | 147 --- tdeio/tdeio/kprotocolmanager.cpp | 534 ----------- tdeio/tdeio/kprotocolmanager.h | 389 -------- tdeio/tdeio/tdeemailsettings.cpp | 272 ++++++ tdeio/tdeio/tdeemailsettings.h | 147 +++ tdeio/tdeio/tdeprotocolmanager.cpp | 534 +++++++++++ tdeio/tdeio/tdeprotocolmanager.h | 389 ++++++++ 12 files changed, 4032 insertions(+), 4032 deletions(-) delete mode 100644 tdeio/tdefile/kdiroperator.cpp delete mode 100644 tdeio/tdefile/kdiroperator.h create mode 100644 tdeio/tdefile/tdediroperator.cpp create mode 100644 tdeio/tdefile/tdediroperator.h delete mode 100644 tdeio/tdeio/kemailsettings.cpp delete mode 100644 tdeio/tdeio/kemailsettings.h delete mode 100644 tdeio/tdeio/kprotocolmanager.cpp delete mode 100644 tdeio/tdeio/kprotocolmanager.h create mode 100644 tdeio/tdeio/tdeemailsettings.cpp create mode 100644 tdeio/tdeio/tdeemailsettings.h create mode 100644 tdeio/tdeio/tdeprotocolmanager.cpp create mode 100644 tdeio/tdeio/tdeprotocolmanager.h (limited to 'tdeio') diff --git a/tdeio/tdefile/kdiroperator.cpp b/tdeio/tdefile/kdiroperator.cpp deleted file mode 100644 index dc44aa8ba..000000000 --- a/tdeio/tdefile/kdiroperator.cpp +++ /dev/null @@ -1,1740 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999,2000 Stephan Kulow - 1999,2000,2001,2002,2003 Carsten Pfeiffer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config-tdefile.h" -#include "kcombiview.h" -#include "tdediroperator.h" -#include "tdefiledetailview.h" -#include "tdefileiconview.h" -#include "tdefilepreview.h" -#include "tdefileview.h" -#include "tdefileitem.h" -#include "tdefilemetapreview.h" - - -template class TQPtrStack; -template class TQDict; - - -class KDirOperator::KDirOperatorPrivate -{ -public: - KDirOperatorPrivate() { - onlyDoubleClickSelectsFiles = false; - progressDelayTimer = 0L; - dirHighlighting = false; - config = 0L; - dropOptions = 0; - } - - ~KDirOperatorPrivate() { - delete progressDelayTimer; - } - - bool dirHighlighting; - TQString lastURL; // used for highlighting a directory on cdUp - bool onlyDoubleClickSelectsFiles; - TQTimer *progressDelayTimer; - TDEActionSeparator *viewActionSeparator; - int dropOptions; - - TDEConfig *config; - TQString configGroup; -}; - -KDirOperator::KDirOperator(const KURL& _url, - TQWidget *parent, const char* _name) - : TQWidget(parent, _name), - dir(0), - m_fileView(0), - progress(0) -{ - myPreview = 0L; - myMode = KFile::File; - m_viewKind = KFile::Simple; - mySorting = static_cast(TQDir::Name | TQDir::DirsFirst); - d = new KDirOperatorPrivate; - - if (_url.isEmpty()) { // no dir specified -> current dir - TQString strPath = TQDir::currentDirPath(); - strPath.append('/'); - currUrl = KURL(); - currUrl.setProtocol(TQString::fromLatin1("file")); - currUrl.setPath(strPath); - } - else { - currUrl = _url; - if ( currUrl.protocol().isEmpty() ) - currUrl.setProtocol(TQString::fromLatin1("file")); - - currUrl.addPath("/"); // make sure we have a trailing slash! - } - - setDirLister( new KDirLister( true ) ); - - connect(&myCompletion, TQT_SIGNAL(match(const TQString&)), - TQT_SLOT(slotCompletionMatch(const TQString&))); - - progress = new KProgress(this, "progress"); - progress->adjustSize(); - progress->move(2, height() - progress->height() -2); - - d->progressDelayTimer = new TQTimer( this, "progress delay timer" ); - connect( d->progressDelayTimer, TQT_SIGNAL( timeout() ), - TQT_SLOT( slotShowProgress() )); - - myCompleteListDirty = false; - - backStack.setAutoDelete( true ); - forwardStack.setAutoDelete( true ); - - // action stuff - setupActions(); - setupMenu(); - - setFocusPolicy(TQ_WheelFocus); -} - -KDirOperator::~KDirOperator() -{ - resetCursor(); - if ( m_fileView ) - { - if ( d->config ) - m_fileView->writeConfig( d->config, d->configGroup ); - - delete m_fileView; - m_fileView = 0L; - } - - delete myPreview; - delete dir; - delete d; -} - - -void KDirOperator::setSorting( TQDir::SortSpec spec ) -{ - if ( m_fileView ) - m_fileView->setSorting( spec ); - mySorting = spec; - updateSortActions(); -} - -void KDirOperator::resetCursor() -{ - TQApplication::restoreOverrideCursor(); - progress->hide(); -} - -void KDirOperator::insertViewDependentActions() -{ - // If we have a new view actionCollection(), insert its actions - // into viewActionMenu. - - if( !m_fileView ) - return; - - if ( (viewActionMenu->popupMenu()->count() == 0) || // Not yet initialized or... - (viewActionCollection != m_fileView->actionCollection()) ) // ...changed since. - { - if (viewActionCollection) - { - disconnect( viewActionCollection, TQT_SIGNAL( inserted( TDEAction * )), - this, TQT_SLOT( slotViewActionAdded( TDEAction * ))); - disconnect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )), - this, TQT_SLOT( slotViewActionRemoved( TDEAction * ))); - } - - viewActionMenu->popupMenu()->clear(); -// viewActionMenu->insert( shortAction ); -// viewActionMenu->insert( detailedAction ); -// viewActionMenu->insert( actionSeparator ); - viewActionMenu->insert( myActionCollection->action( "short view" ) ); - viewActionMenu->insert( myActionCollection->action( "detailed view" ) ); - viewActionMenu->insert( actionSeparator ); - viewActionMenu->insert( showHiddenAction ); -// viewActionMenu->insert( myActionCollection->action( "single" )); - viewActionMenu->insert( separateDirsAction ); - // Warning: adjust slotViewActionAdded() and slotViewActionRemoved() - // when you add/remove actions here! - - viewActionCollection = m_fileView->actionCollection(); - if (!viewActionCollection) - return; - - if ( !viewActionCollection->isEmpty() ) - { - viewActionMenu->insert( d->viewActionSeparator ); - - // first insert the normal actions, then the grouped ones - TQStringList groups = viewActionCollection->groups(); - groups.prepend( TQString::null ); // actions without group - TQStringList::ConstIterator git = groups.begin(); - TDEActionPtrList list; - TDEAction *sep = actionCollection()->action("separator"); - for ( ; git != groups.end(); ++git ) - { - if ( git != groups.begin() ) - viewActionMenu->insert( sep ); - - list = viewActionCollection->actions( *git ); - TDEActionPtrList::ConstIterator it = list.begin(); - for ( ; it != list.end(); ++it ) - viewActionMenu->insert( *it ); - } - } - - connect( viewActionCollection, TQT_SIGNAL( inserted( TDEAction * )), - TQT_SLOT( slotViewActionAdded( TDEAction * ))); - connect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )), - TQT_SLOT( slotViewActionRemoved( TDEAction * ))); - } -} - -void KDirOperator::activatedMenu( const KFileItem *, const TQPoint& pos ) -{ - setupMenu(); - updateSelectionDependentActions(); - - actionMenu->popup( pos ); -} - -void KDirOperator::updateSelectionDependentActions() -{ - bool hasSelection = m_fileView && m_fileView->selectedItems() && - !m_fileView->selectedItems()->isEmpty(); - myActionCollection->action( "trash" )->setEnabled( hasSelection ); - myActionCollection->action( "delete" )->setEnabled( hasSelection ); - myActionCollection->action( "properties" )->setEnabled( hasSelection ); -} - -void KDirOperator::setPreviewWidget(const TQWidget *w) -{ - if(w != 0L) - m_viewKind = (m_viewKind | KFile::PreviewContents); - else - m_viewKind = (m_viewKind & ~KFile::PreviewContents); - - delete myPreview; - myPreview = w; - - TDEToggleAction *preview = static_cast(myActionCollection->action("preview")); - preview->setEnabled( w != 0L ); - preview->setChecked( w != 0L ); - setView( static_cast(m_viewKind) ); -} - -int KDirOperator::numDirs() const -{ - return m_fileView ? m_fileView->numDirs() : 0; -} - -int KDirOperator::numFiles() const -{ - return m_fileView ? m_fileView->numFiles() : 0; -} - -void KDirOperator::slotDetailedView() -{ - KFile::FileView view = static_cast( (m_viewKind & ~KFile::Simple) | KFile::Detail ); - setView( view ); -} - -void KDirOperator::slotSimpleView() -{ - KFile::FileView view = static_cast( (m_viewKind & ~KFile::Detail) | KFile::Simple ); - setView( view ); -} - -void KDirOperator::slotToggleHidden( bool show ) -{ - dir->setShowingDotFiles( show ); - updateDir(); - if ( m_fileView ) - m_fileView->listingCompleted(); -} - -void KDirOperator::slotSeparateDirs() -{ - if (separateDirsAction->isChecked()) - { - KFile::FileView view = static_cast( m_viewKind | KFile::SeparateDirs ); - setView( view ); - } - else - { - KFile::FileView view = static_cast( m_viewKind & ~KFile::SeparateDirs ); - setView( view ); - } -} - -void KDirOperator::slotDefaultPreview() -{ - m_viewKind = m_viewKind | KFile::PreviewContents; - if ( !myPreview ) { - myPreview = new KFileMetaPreview( this ); - (static_cast( myActionCollection->action("preview") ))->setChecked(true); - } - - setView( static_cast(m_viewKind) ); -} - -void KDirOperator::slotSortByName() -{ - int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask; - m_fileView->setSorting( static_cast( sorting | TQDir::Name )); - mySorting = m_fileView->sorting(); - caseInsensitiveAction->setEnabled( true ); -} - -void KDirOperator::slotSortBySize() -{ - int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask; - m_fileView->setSorting( static_cast( sorting | TQDir::Size )); - mySorting = m_fileView->sorting(); - caseInsensitiveAction->setEnabled( false ); -} - -void KDirOperator::slotSortByDate() -{ - int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask; - m_fileView->setSorting( static_cast( sorting | TQDir::Time )); - mySorting = m_fileView->sorting(); - caseInsensitiveAction->setEnabled( false ); -} - -void KDirOperator::slotSortReversed() -{ - if ( m_fileView ) - m_fileView->sortReversed(); -} - -void KDirOperator::slotToggleDirsFirst() -{ - TQDir::SortSpec sorting = m_fileView->sorting(); - if ( !KFile::isSortDirsFirst( sorting ) ) - m_fileView->setSorting( static_cast( sorting | TQDir::DirsFirst )); - else - m_fileView->setSorting( static_cast( sorting & ~TQDir::DirsFirst)); - mySorting = m_fileView->sorting(); -} - -void KDirOperator::slotToggleIgnoreCase() -{ - TQDir::SortSpec sorting = m_fileView->sorting(); - if ( !KFile::isSortCaseInsensitive( sorting ) ) - m_fileView->setSorting( static_cast( sorting | TQDir::IgnoreCase )); - else - m_fileView->setSorting( static_cast( sorting & ~TQDir::IgnoreCase)); - mySorting = m_fileView->sorting(); -} - -void KDirOperator::mkdir() -{ - bool ok; - TQString where = url().pathOrURL(); - TQString name = i18n( "New Folder" ); - if ( url().isLocalFile() && TQFileInfo( url().path(+1) + name ).exists() ) - name = TDEIO::RenameDlg::suggestName( url(), name ); - - TQString dir = KInputDialog::getText( i18n( "New Folder" ), - i18n( "Create new folder in:\n%1" ).arg( where ), - name, &ok, this); - if (ok) - mkdir( TDEIO::encodeFileName( dir ), true ); -} - -bool KDirOperator::mkdir( const TQString& directory, bool enterDirectory ) -{ - // Creates "directory", relative to the current directory (currUrl). - // The given path may contain any number directories, existant or not. - // They will all be created, if possible. - - bool writeOk = false; - bool exists = false; - KURL url( currUrl ); - - TQStringList dirs = TQStringList::split( TQDir::separator(), directory ); - TQStringList::ConstIterator it = dirs.begin(); - - for ( ; it != dirs.end(); ++it ) - { - url.addPath( *it ); - exists = TDEIO::NetAccess::exists( url, false, 0 ); - writeOk = !exists && TDEIO::NetAccess::mkdir( url, topLevelWidget() ); - } - - if ( exists ) // url was already existant - { - KMessageBox::sorry(viewWidget(), i18n("A file or folder named %1 already exists.").arg(url.pathOrURL())); - enterDirectory = false; - } - else if ( !writeOk ) { - KMessageBox::sorry(viewWidget(), i18n("You do not have permission to " - "create that folder." )); - } - else if ( enterDirectory ) { - setURL( url, true ); - } - - return writeOk; -} - -TDEIO::DeleteJob * KDirOperator::del( const KFileItemList& items, - bool ask, bool showProgress ) -{ - return del( items, this, ask, showProgress ); -} - -TDEIO::DeleteJob * KDirOperator::del( const KFileItemList& items, - TQWidget *parent, - bool ask, bool showProgress ) -{ - if ( items.isEmpty() ) { - KMessageBox::information( parent, - i18n("You did not select a file to delete."), - i18n("Nothing to Delete") ); - return 0L; - } - - KURL::List urls; - TQStringList files; - KFileItemListIterator it( items ); - - for ( ; it.current(); ++it ) { - KURL url = (*it)->url(); - urls.append( url ); - if ( url.isLocalFile() ) - files.append( url.path() ); - else - files.append( url.prettyURL() ); - } - - bool doIt = !ask; - if ( ask ) { - int ret; - if ( items.count() == 1 ) { - ret = KMessageBox::warningContinueCancel( parent, - i18n( "Do you really want to delete\n '%1'?" ) - .arg( files.first() ), - i18n("Delete File"), - KStdGuiItem::del(), "AskForDelete" ); - } - else - ret = KMessageBox::warningContinueCancelList( parent, - i18n("Do you really want to delete this item?", "Do you really want to delete these %n items?", items.count() ), - files, - i18n("Delete Files"), - KStdGuiItem::del(), "AskForDelete" ); - doIt = (ret == KMessageBox::Continue); - } - - if ( doIt ) { - TDEIO::DeleteJob *job = TDEIO::del( urls, false, showProgress ); - job->setWindow (topLevelWidget()); - job->setAutoErrorHandlingEnabled( true, parent ); - return job; - } - - return 0L; -} - -void KDirOperator::deleteSelected() -{ - if ( !m_fileView ) - return; - - const KFileItemList *list = m_fileView->selectedItems(); - if ( list ) - del( *list ); -} - -TDEIO::CopyJob * KDirOperator::trash( const KFileItemList& items, - TQWidget *parent, - bool ask, bool showProgress ) -{ - if ( items.isEmpty() ) { - KMessageBox::information( parent, - i18n("You did not select a file to trash."), - i18n("Nothing to Trash") ); - return 0L; - } - - KURL::List urls; - TQStringList files; - KFileItemListIterator it( items ); - - for ( ; it.current(); ++it ) { - KURL url = (*it)->url(); - urls.append( url ); - if ( url.isLocalFile() ) - files.append( url.path() ); - else - files.append( url.prettyURL() ); - } - - bool doIt = !ask; - if ( ask ) { - int ret; - if ( items.count() == 1 ) { - ret = KMessageBox::warningContinueCancel( parent, - i18n( "Do you really want to trash\n '%1'?" ) - .arg( files.first() ), - i18n("Trash File"), - KGuiItem(i18n("to trash", "&Trash"),"edittrash"), "AskForTrash" ); - } - else - ret = KMessageBox::warningContinueCancelList( parent, - i18n("translators: not called for n == 1", "Do you really want to trash these %n items?", items.count() ), - files, - i18n("Trash Files"), - KGuiItem(i18n("to trash", "&Trash"),"edittrash"), "AskForTrash" ); - doIt = (ret == KMessageBox::Continue); - } - - if ( doIt ) { - TDEIO::CopyJob *job = TDEIO::trash( urls, showProgress ); - job->setWindow (topLevelWidget()); - job->setAutoErrorHandlingEnabled( true, parent ); - return job; - } - - return 0L; -} - -void KDirOperator::trashSelected(TDEAction::ActivationReason reason, TQt::ButtonState state) -{ - if ( !m_fileView ) - return; - - if ( reason == TDEAction::PopupMenuActivation && ( state & ShiftButton ) ) { - deleteSelected(); - return; - } - - const KFileItemList *list = m_fileView->selectedItems(); - if ( list ) - trash( *list, this ); -} - -void KDirOperator::close() -{ - resetCursor(); - pendingMimeTypes.clear(); - myCompletion.clear(); - myDirCompletion.clear(); - myCompleteListDirty = true; - dir->stop(); -} - -void KDirOperator::checkPath(const TQString &, bool /*takeFiles*/) // SLOT -{ -#if 0 - // copy the argument in a temporary string - TQString text = _txt; - // it's unlikely to happen, that at the beginning are spaces, but - // for the end, it happens quite often, I guess. - text = text.stripWhiteSpace(); - // if the argument is no URL (the check is quite fragil) and it's - // no absolute path, we add the current directory to get a correct url - if (text.find(':') < 0 && text[0] != '/') - text.insert(0, currUrl); - - // in case we have a selection defined and someone patched the file- - // name, we check, if the end of the new name is changed. - if (!selection.isNull()) { - int position = text.findRev('/'); - ASSERT(position >= 0); // we already inserted the current dir in case - TQString filename = text.mid(position + 1, text.length()); - if (filename != selection) - selection = TQString::null; - } - - KURL u(text); // I have to take care of entered URLs - bool filenameEntered = false; - - if (u.isLocalFile()) { - // the empty path is kind of a hack - KFileItem i("", u.path()); - if (i.isDir()) - setURL(text, true); - else { - if (takeFiles) - if (acceptOnlyExisting && !i.isFile()) - warning("you entered an invalid URL"); - else - filenameEntered = true; - } - } else - setURL(text, true); - - if (filenameEntered) { - filename_ = u.url(); - emit fileSelected(filename_); - - TQApplication::restoreOverrideCursor(); - - accept(); - } -#endif - kdDebug(tdefile_area) << "TODO KDirOperator::checkPath()" << endl; -} - -void KDirOperator::setURL(const KURL& _newurl, bool clearforward) -{ - KURL newurl; - - if ( !_newurl.isValid() ) - newurl.setPath( TQDir::homeDirPath() ); - else - newurl = _newurl; - - TQString pathstr = newurl.path(+1); - newurl.setPath(pathstr); - - // already set - if ( newurl.equals( currUrl, true ) ) - return; - - if ( !isReadable( newurl ) ) { - // maybe newurl is a file? check its parent directory - newurl.cd(TQString::fromLatin1("..")); - if ( !isReadable( newurl ) ) { - resetCursor(); - KMessageBox::error(viewWidget(), - i18n("The specified folder does not exist " - "or was not readable.")); - return; - } - } - - if (clearforward) { - // autodelete should remove this one - backStack.push(new KURL(currUrl)); - forwardStack.clear(); - } - - d->lastURL = currUrl.url(-1); - currUrl = newurl; - - pathChanged(); - emit urlEntered(newurl); - - // enable/disable actions - forwardAction->setEnabled( !forwardStack.isEmpty() ); - backAction->setEnabled( !backStack.isEmpty() ); - upAction->setEnabled( !isRoot() ); - - openURL( newurl ); -} - -void KDirOperator::updateDir() -{ - dir->emitChanges(); - if ( m_fileView ) - m_fileView->listingCompleted(); -} - -void KDirOperator::rereadDir() -{ - pathChanged(); - openURL( currUrl, false, true ); -} - - -bool KDirOperator::openURL( const KURL& url, bool keep, bool reload ) -{ - bool result = dir->openURL( url, keep, reload ); - if ( !result ) // in that case, neither completed() nor canceled() will be emitted by KDL - slotCanceled(); - - return result; -} - -// Protected -void KDirOperator::pathChanged() -{ - if (!m_fileView) - return; - - pendingMimeTypes.clear(); - m_fileView->clear(); - myCompletion.clear(); - myDirCompletion.clear(); - - // it may be, that we weren't ready at this time - TQApplication::restoreOverrideCursor(); - - // when TDEIO::Job emits finished, the slot will restore the cursor - TQApplication::setOverrideCursor( tqwaitCursor ); - - if ( !isReadable( currUrl )) { - KMessageBox::error(viewWidget(), - i18n("The specified folder does not exist " - "or was not readable.")); - if (backStack.isEmpty()) - home(); - else - back(); - } -} - -void KDirOperator::slotRedirected( const KURL& newURL ) -{ - currUrl = newURL; - pendingMimeTypes.clear(); - myCompletion.clear(); - myDirCompletion.clear(); - myCompleteListDirty = true; - emit urlEntered( newURL ); -} - -// Code pinched from kfm then hacked -void KDirOperator::back() -{ - if ( backStack.isEmpty() ) - return; - - forwardStack.push( new KURL(currUrl) ); - - KURL *s = backStack.pop(); - - setURL(*s, false); - delete s; -} - -// Code pinched from kfm then hacked -void KDirOperator::forward() -{ - if ( forwardStack.isEmpty() ) - return; - - backStack.push(new KURL(currUrl)); - - KURL *s = forwardStack.pop(); - setURL(*s, false); - delete s; -} - -KURL KDirOperator::url() const -{ - return currUrl; -} - -void KDirOperator::cdUp() -{ - KURL tmp(currUrl); - tmp.cd(TQString::fromLatin1("..")); - setURL(tmp, true); -} - -void KDirOperator::home() -{ - KURL u; - u.setPath( TQDir::homeDirPath() ); - setURL(u, true); -} - -void KDirOperator::clearFilter() -{ - dir->setNameFilter( TQString::null ); - dir->clearMimeFilter(); - checkPreviewSupport(); -} - -void KDirOperator::setNameFilter(const TQString& filter) -{ - dir->setNameFilter(filter); - checkPreviewSupport(); -} - -void KDirOperator::setMimeFilter( const TQStringList& mimetypes ) -{ - dir->setMimeFilter( mimetypes ); - checkPreviewSupport(); -} - -bool KDirOperator::checkPreviewSupport() -{ - TDEToggleAction *previewAction = static_cast( myActionCollection->action( "preview" )); - - bool hasPreviewSupport = false; - TDEConfig *kc = TDEGlobal::config(); - TDEConfigGroupSaver cs( kc, ConfigGroup ); - if ( kc->readBoolEntry( "Show Default Preview", true ) ) - hasPreviewSupport = checkPreviewInternal(); - - previewAction->setEnabled( hasPreviewSupport ); - return hasPreviewSupport; -} - -bool KDirOperator::checkPreviewInternal() const -{ - TQStringList supported = TDEIO::PreviewJob::supportedMimeTypes(); - // no preview support for directories? - if ( dirOnlyMode() && supported.findIndex( "inode/directory" ) == -1 ) - return false; - - TQStringList mimeTypes = dir->mimeFilters(); - TQStringList nameFilter = TQStringList::split( " ", dir->nameFilter() ); - - if ( mimeTypes.isEmpty() && nameFilter.isEmpty() && !supported.isEmpty() ) - return true; - else { - TQRegExp r; - r.setWildcard( true ); // the "mimetype" can be "image/*" - - if ( !mimeTypes.isEmpty() ) { - TQStringList::Iterator it = supported.begin(); - - for ( ; it != supported.end(); ++it ) { - r.setPattern( *it ); - - TQStringList result = mimeTypes.grep( r ); - if ( !result.isEmpty() ) { // matches! -> we want previews - return true; - } - } - } - - if ( !nameFilter.isEmpty() ) { - // find the mimetypes of all the filter-patterns and - KServiceTypeFactory *fac = KServiceTypeFactory::self(); - TQStringList::Iterator it1 = nameFilter.begin(); - for ( ; it1 != nameFilter.end(); ++it1 ) { - if ( (*it1) == "*" ) { - return true; - } - - KMimeType *mt = fac->findFromPattern( *it1 ); - if ( !mt ) - continue; - TQString mime = mt->name(); - delete mt; - - // the "mimetypes" we get from the PreviewJob can be "image/*" - // so we need to check in wildcard mode - TQStringList::Iterator it2 = supported.begin(); - for ( ; it2 != supported.end(); ++it2 ) { - r.setPattern( *it2 ); - if ( r.search( mime ) != -1 ) { - return true; - } - } - } - } - } - - return false; -} - -KFileView* KDirOperator::createView( TQWidget* parent, KFile::FileView view ) -{ - KFileView* new_view = 0L; - bool separateDirs = KFile::isSeparateDirs( view ); - bool preview = ( KFile::isPreviewInfo(view) || KFile::isPreviewContents( view ) ); - - if ( separateDirs || preview ) { - KCombiView *combi = 0L; - if (separateDirs) - { - combi = new KCombiView( parent, "combi view" ); - combi->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles); - } - - KFileView* v = 0L; - if ( KFile::isSimpleView( view ) ) - v = createView( combi, KFile::Simple ); - else - v = createView( combi, KFile::Detail ); - - v->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles); - - if (combi) - combi->setRight( v ); - - if (preview) - { - KFilePreview* pView = new KFilePreview( combi ? combi : v, parent, "preview" ); - pView->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles); - new_view = pView; - } - else - new_view = combi; - } - else if ( KFile::isDetailView( view ) && !preview ) { - new_view = new KFileDetailView( parent, "detail view"); - new_view->setViewName( i18n("Detailed View") ); - } - else /* if ( KFile::isSimpleView( view ) && !preview ) */ { - KFileIconView *iconView = new KFileIconView( parent, "simple view"); - new_view = iconView; - new_view->setViewName( i18n("Short View") ); - } - - new_view->widget()->setAcceptDrops(acceptDrops()); - return new_view; -} - -void KDirOperator::setAcceptDrops(bool b) -{ - if (m_fileView) - m_fileView->widget()->setAcceptDrops(b); - TQWidget::setAcceptDrops(b); -} - -void KDirOperator::setDropOptions(int options) -{ - d->dropOptions = options; - if (m_fileView) - m_fileView->setDropOptions(options); -} - -void KDirOperator::setView( KFile::FileView view ) -{ - bool separateDirs = KFile::isSeparateDirs( view ); - bool preview=( KFile::isPreviewInfo(view) || KFile::isPreviewContents( view ) ); - - if (view == KFile::Default) { - if ( KFile::isDetailView( (KFile::FileView) defaultView ) ) - view = KFile::Detail; - else - view = KFile::Simple; - - separateDirs = KFile::isSeparateDirs( static_cast(defaultView) ); - preview = ( KFile::isPreviewInfo( static_cast(defaultView) ) || - KFile::isPreviewContents( static_cast(defaultView) ) ) - && myActionCollection->action("preview")->isEnabled(); - - if ( preview ) { // instantiates KFileMetaPreview and calls setView() - m_viewKind = defaultView; - slotDefaultPreview(); - return; - } - else if ( !separateDirs ) - separateDirsAction->setChecked(true); - } - - // if we don't have any files, we can't separate dirs from files :) - if ( (mode() & KFile::File) == 0 && - (mode() & KFile::Files) == 0 ) { - separateDirs = false; - separateDirsAction->setEnabled( false ); - } - - m_viewKind = static_cast(view) | (separateDirs ? KFile::SeparateDirs : 0); - view = static_cast(m_viewKind); - - KFileView *new_view = createView( this, view ); - if ( preview ) { - // we keep the preview-_widget_ around, but not the KFilePreview. - // KFilePreview::setPreviewWidget handles the reparenting for us - static_cast(new_view)->setPreviewWidget(myPreview, url()); - } - - setView( new_view ); -} - - -void KDirOperator::connectView(KFileView *view) -{ - // TODO: do a real timer and restart it after that - pendingMimeTypes.clear(); - bool listDir = true; - - if ( dirOnlyMode() ) - view->setViewMode(KFileView::Directories); - else - view->setViewMode(KFileView::All); - - if ( myMode & KFile::Files ) - view->setSelectionMode( KFile::Extended ); - else - view->setSelectionMode( KFile::Single ); - - if (m_fileView) - { - if ( d->config ) // save and restore the views' configuration - { - m_fileView->writeConfig( d->config, d->configGroup ); - view->readConfig( d->config, d->configGroup ); - } - - // transfer the state from old view to new view - view->clear(); - view->addItemList( *m_fileView->items() ); - listDir = false; - - if ( m_fileView->widget()->hasFocus() ) - view->widget()->setFocus(); - - KFileItem *oldCurrentItem = m_fileView->currentFileItem(); - if ( oldCurrentItem ) { - view->setCurrentItem( oldCurrentItem ); - view->setSelected( oldCurrentItem, false ); - view->ensureItemVisible( oldCurrentItem ); - } - - const KFileItemList *oldSelected = m_fileView->selectedItems(); - if ( !oldSelected->isEmpty() ) { - KFileItemListIterator it( *oldSelected ); - for ( ; it.current(); ++it ) - view->setSelected( it.current(), true ); - } - - m_fileView->widget()->hide(); - delete m_fileView; - } - - else - { - if ( d->config ) - view->readConfig( d->config, d->configGroup ); - } - - m_fileView = view; - m_fileView->setDropOptions(d->dropOptions); - viewActionCollection = 0L; - KFileViewSignaler *sig = view->signaler(); - - connect(sig, TQT_SIGNAL( activatedMenu(const KFileItem *, const TQPoint& ) ), - this, TQT_SLOT( activatedMenu(const KFileItem *, const TQPoint& ))); - connect(sig, TQT_SIGNAL( dirActivated(const KFileItem *) ), - this, TQT_SLOT( selectDir(const KFileItem*) ) ); - connect(sig, TQT_SIGNAL( fileSelected(const KFileItem *) ), - this, TQT_SLOT( selectFile(const KFileItem*) ) ); - connect(sig, TQT_SIGNAL( fileHighlighted(const KFileItem *) ), - this, TQT_SLOT( highlightFile(const KFileItem*) )); - connect(sig, TQT_SIGNAL( sortingChanged( TQDir::SortSpec ) ), - this, TQT_SLOT( slotViewSortingChanged( TQDir::SortSpec ))); - connect(sig, TQT_SIGNAL( dropped(const KFileItem *, TQDropEvent*, const KURL::List&) ), - this, TQT_SIGNAL( dropped(const KFileItem *, TQDropEvent*, const KURL::List&)) ); - - if ( reverseAction->isChecked() != m_fileView->isReversed() ) - slotSortReversed(); - - updateViewActions(); - m_fileView->widget()->resize(size()); - m_fileView->widget()->show(); - - if ( listDir ) { - TQApplication::setOverrideCursor( tqwaitCursor ); - openURL( currUrl ); - } - else - view->listingCompleted(); -} - -KFile::Mode KDirOperator::mode() const -{ - return myMode; -} - -void KDirOperator::setMode(KFile::Mode m) -{ - if (myMode == m) - return; - - myMode = m; - - dir->setDirOnlyMode( dirOnlyMode() ); - - // reset the view with the different mode - setView( static_cast(m_viewKind) ); -} - -void KDirOperator::setView(KFileView *view) -{ - if ( view == m_fileView ) { - return; - } - - setFocusProxy(view->widget()); - view->setSorting( mySorting ); - view->setOnlyDoubleClickSelectsFiles( d->onlyDoubleClickSelectsFiles ); - connectView(view); // also deletes the old view - - emit viewChanged( view ); -} - -void KDirOperator::setDirLister( KDirLister *lister ) -{ - if ( lister == dir ) // sanity check - return; - - delete dir; - dir = lister; - - dir->setAutoUpdate( true ); - - TQWidget* mainWidget = topLevelWidget(); - dir->setMainWindow (mainWidget); - kdDebug (tdefile_area) << "mainWidget=" << mainWidget << endl; - - connect( dir, TQT_SIGNAL( percent( int )), - TQT_SLOT( slotProgress( int ) )); - connect( dir, TQT_SIGNAL(started( const KURL& )), TQT_SLOT(slotStarted())); - connect( dir, TQT_SIGNAL(newItems(const KFileItemList &)), - TQT_SLOT(insertNewFiles(const KFileItemList &))); - connect( dir, TQT_SIGNAL(completed()), TQT_SLOT(slotIOFinished())); - connect( dir, TQT_SIGNAL(canceled()), TQT_SLOT(slotCanceled())); - connect( dir, TQT_SIGNAL(deleteItem(KFileItem *)), - TQT_SLOT(itemDeleted(KFileItem *))); - connect( dir, TQT_SIGNAL(redirection( const KURL& )), - TQT_SLOT( slotRedirected( const KURL& ))); - connect( dir, TQT_SIGNAL( clear() ), TQT_SLOT( slotClearView() )); - connect( dir, TQT_SIGNAL( refreshItems( const KFileItemList& ) ), - TQT_SLOT( slotRefreshItems( const KFileItemList& ) ) ); -} - -void KDirOperator::insertNewFiles(const KFileItemList &newone) -{ - if ( newone.isEmpty() || !m_fileView ) - return; - - myCompleteListDirty = true; - m_fileView->addItemList( newone ); - emit updateInformation(m_fileView->numDirs(), m_fileView->numFiles()); - - KFileItem *item; - KFileItemListIterator it( newone ); - - while ( (item = it.current()) ) { - // highlight the dir we come from, if possible - if ( d->dirHighlighting && item->isDir() && - item->url().url(-1) == d->lastURL ) { - m_fileView->setCurrentItem( item ); - m_fileView->ensureItemVisible( item ); - } - - ++it; - } - - TQTimer::singleShot(200, this, TQT_SLOT(resetCursor())); -} - -void KDirOperator::selectDir(const KFileItem *item) -{ - setURL(item->url(), true); -} - -void KDirOperator::itemDeleted(KFileItem *item) -{ - pendingMimeTypes.removeRef( item ); - if ( m_fileView ) - { - m_fileView->removeItem( static_cast( item )); - emit updateInformation(m_fileView->numDirs(), m_fileView->numFiles()); - } -} - -void KDirOperator::selectFile(const KFileItem *item) -{ - TQApplication::restoreOverrideCursor(); - - emit fileSelected( item ); -} - -void KDirOperator::setCurrentItem( const TQString& filename ) -{ - if ( m_fileView ) { - const KFileItem *item = 0L; - - if ( !filename.isNull() ) - item = static_cast(dir->findByName( filename )); - - m_fileView->clearSelection(); - if ( item ) { - m_fileView->setCurrentItem( item ); - m_fileView->setSelected( item, true ); - m_fileView->ensureItemVisible( item ); - } - } -} - -TQString KDirOperator::makeCompletion(const TQString& string) -{ - if ( string.isEmpty() ) { - m_fileView->clearSelection(); - return TQString::null; - } - - prepareCompletionObjects(); - return myCompletion.makeCompletion( string ); -} - -TQString KDirOperator::makeDirCompletion(const TQString& string) -{ - if ( string.isEmpty() ) { - m_fileView->clearSelection(); - return TQString::null; - } - - prepareCompletionObjects(); - return myDirCompletion.makeCompletion( string ); -} - -void KDirOperator::prepareCompletionObjects() -{ - if ( !m_fileView ) - return; - - if ( myCompleteListDirty ) { // create the list of all possible completions - KFileItemListIterator it( *(m_fileView->items()) ); - for( ; it.current(); ++it ) { - KFileItem *item = it.current(); - - myCompletion.addItem( item->name() ); - if ( item->isDir() ) - myDirCompletion.addItem( item->name() ); - } - myCompleteListDirty = false; - } -} - -void KDirOperator::slotCompletionMatch(const TQString& match) -{ - setCurrentItem( match ); - emit completion( match ); -} - -void KDirOperator::setupActions() -{ - myActionCollection = new TDEActionCollection( topLevelWidget(), TQT_TQOBJECT(this), "KDirOperator::myActionCollection" ); - - actionMenu = new TDEActionMenu( i18n("Menu"), myActionCollection, "popupMenu" ); - upAction = KStdAction::up( TQT_TQOBJECT(this), TQT_SLOT( cdUp() ), myActionCollection, "up" ); - upAction->setText( i18n("Parent Folder") ); - backAction = KStdAction::back( TQT_TQOBJECT(this), TQT_SLOT( back() ), myActionCollection, "back" ); - forwardAction = KStdAction::forward( TQT_TQOBJECT(this), TQT_SLOT(forward()), myActionCollection, "forward" ); - homeAction = KStdAction::home( TQT_TQOBJECT(this), TQT_SLOT( home() ), myActionCollection, "home" ); - homeAction->setText(i18n("Home Folder")); - reloadAction = KStdAction::redisplay( TQT_TQOBJECT(this), TQT_SLOT(rereadDir()), myActionCollection, "reload" ); - actionSeparator = new TDEActionSeparator( myActionCollection, "separator" ); - d->viewActionSeparator = new TDEActionSeparator( myActionCollection, - "viewActionSeparator" ); - mkdirAction = new TDEAction( i18n("New Folder..."), 0, - TQT_TQOBJECT(this), TQT_SLOT( mkdir() ), myActionCollection, "mkdir" ); - TDEAction* trash = new TDEAction( i18n( "Move to Trash" ), "edittrash", Key_Delete, myActionCollection, "trash" ); - connect( trash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ), - this, TQT_SLOT( trashSelected( TDEAction::ActivationReason, TQt::ButtonState ) ) ); - new TDEAction( i18n( "Delete" ), "editdelete", SHIFT+Key_Delete, TQT_TQOBJECT(this), - TQT_SLOT( deleteSelected() ), myActionCollection, "delete" ); - mkdirAction->setIcon( TQString::fromLatin1("folder_new") ); - reloadAction->setText( i18n("Reload") ); - reloadAction->setShortcut( TDEStdAccel::shortcut( TDEStdAccel::Reload )); - - - // the sort menu actions - sortActionMenu = new TDEActionMenu( i18n("Sorting"), myActionCollection, "sorting menu"); - byNameAction = new TDERadioAction( i18n("By Name"), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotSortByName() ), - myActionCollection, "by name" ); - byDateAction = new TDERadioAction( i18n("By Date"), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotSortByDate() ), - myActionCollection, "by date" ); - bySizeAction = new TDERadioAction( i18n("By Size"), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotSortBySize() ), - myActionCollection, "by size" ); - reverseAction = new TDEToggleAction( i18n("Reverse"), 0, - TQT_TQOBJECT(this), TQT_SLOT( slotSortReversed() ), - myActionCollection, "reversed" ); - - TQString sortGroup = TQString::fromLatin1("sort"); - byNameAction->setExclusiveGroup( sortGroup ); - byDateAction->setExclusiveGroup( sortGroup ); - bySizeAction->setExclusiveGroup( sortGroup ); - - - dirsFirstAction = new TDEToggleAction( i18n("Folders First"), 0, - myActionCollection, "dirs first"); - caseInsensitiveAction = new TDEToggleAction(i18n("Case Insensitive"), 0, - myActionCollection, "case insensitive" ); - - connect( dirsFirstAction, TQT_SIGNAL( toggled( bool ) ), - TQT_SLOT( slotToggleDirsFirst() )); - connect( caseInsensitiveAction, TQT_SIGNAL( toggled( bool ) ), - TQT_SLOT( slotToggleIgnoreCase() )); - - - - // the view menu actions - viewActionMenu = new TDEActionMenu( i18n("&View"), myActionCollection, "view menu" ); - connect( viewActionMenu->popupMenu(), TQT_SIGNAL( aboutToShow() ), - TQT_SLOT( insertViewDependentActions() )); - - shortAction = new TDERadioAction( i18n("Short View"), "view_multicolumn", - TDEShortcut(), myActionCollection, "short view" ); - detailedAction = new TDERadioAction( i18n("Detailed View"), "view_detailed", - TDEShortcut(), myActionCollection, "detailed view" ); - - showHiddenAction = new TDEToggleAction( i18n("Show Hidden Files"), TDEShortcut(), - myActionCollection, "show hidden" ); -// showHiddenAction->setCheckedState( i18n("Hide Hidden Files") ); - separateDirsAction = new TDEToggleAction( i18n("Separate Folders"), TDEShortcut(), - TQT_TQOBJECT(this), - TQT_SLOT(slotSeparateDirs()), - myActionCollection, "separate dirs" ); - TDEToggleAction *previewAction = new TDEToggleAction(i18n("Show Preview"), - "thumbnail", TDEShortcut(), - myActionCollection, - "preview" ); - previewAction->setCheckedState(i18n("Hide Preview")); - connect( previewAction, TQT_SIGNAL( toggled( bool )), - TQT_SLOT( togglePreview( bool ))); - - - TQString viewGroup = TQString::fromLatin1("view"); - shortAction->setExclusiveGroup( viewGroup ); - detailedAction->setExclusiveGroup( viewGroup ); - - connect( shortAction, TQT_SIGNAL( activated() ), - TQT_SLOT( slotSimpleView() )); - connect( detailedAction, TQT_SIGNAL( activated() ), - TQT_SLOT( slotDetailedView() )); - connect( showHiddenAction, TQT_SIGNAL( toggled( bool ) ), - TQT_SLOT( slotToggleHidden( bool ) )); - - new TDEAction( i18n("Properties"), TDEShortcut(ALT+Key_Return), TQT_TQOBJECT(this), - TQT_SLOT(slotProperties()), myActionCollection, "properties" ); -} - -void KDirOperator::setupMenu() -{ - setupMenu(AllActions); -} - -void KDirOperator::setupMenu(int whichActions) -{ - // first fill the submenus (sort and view) - sortActionMenu->popupMenu()->clear(); - sortActionMenu->insert( byNameAction ); - sortActionMenu->insert( byDateAction ); - sortActionMenu->insert( bySizeAction ); - sortActionMenu->insert( actionSeparator ); - sortActionMenu->insert( reverseAction ); - sortActionMenu->insert( dirsFirstAction ); - sortActionMenu->insert( caseInsensitiveAction ); - - // now plug everything into the popupmenu - actionMenu->popupMenu()->clear(); - if (whichActions & NavActions) - { - actionMenu->insert( upAction ); - actionMenu->insert( backAction ); - actionMenu->insert( forwardAction ); - actionMenu->insert( homeAction ); - actionMenu->insert( actionSeparator ); - } - - if (whichActions & FileActions) - { - actionMenu->insert( mkdirAction ); - if (currUrl.isLocalFile() && !(TDEApplication::keyboardMouseState() & TQt::ShiftButton)) - actionMenu->insert( myActionCollection->action( "trash" ) ); - TDEConfig *globalconfig = TDEGlobal::config(); - TDEConfigGroupSaver cs( globalconfig, TQString::fromLatin1("KDE") ); - if (!currUrl.isLocalFile() || (TDEApplication::keyboardMouseState() & TQt::ShiftButton) || - globalconfig->readBoolEntry("ShowDeleteCommand", false)) - actionMenu->insert( myActionCollection->action( "delete" ) ); - actionMenu->insert( actionSeparator ); - } - - if (whichActions & SortActions) - { - actionMenu->insert( sortActionMenu ); - actionMenu->insert( actionSeparator ); - } - - if (whichActions & ViewActions) - { - actionMenu->insert( viewActionMenu ); - actionMenu->insert( actionSeparator ); - } - - if (whichActions & FileActions) - { - actionMenu->insert( myActionCollection->action( "properties" ) ); - } -} - -void KDirOperator::updateSortActions() -{ - if ( KFile::isSortByName( mySorting ) ) - byNameAction->setChecked( true ); - else if ( KFile::isSortByDate( mySorting ) ) - byDateAction->setChecked( true ); - else if ( KFile::isSortBySize( mySorting ) ) - bySizeAction->setChecked( true ); - - dirsFirstAction->setChecked( KFile::isSortDirsFirst( mySorting ) ); - caseInsensitiveAction->setChecked( KFile::isSortCaseInsensitive(mySorting) ); - caseInsensitiveAction->setEnabled( KFile::isSortByName( mySorting ) ); - - if ( m_fileView ) - reverseAction->setChecked( m_fileView->isReversed() ); -} - -void KDirOperator::updateViewActions() -{ - KFile::FileView fv = static_cast( m_viewKind ); - - separateDirsAction->setChecked( KFile::isSeparateDirs( fv ) && - separateDirsAction->isEnabled() ); - - shortAction->setChecked( KFile::isSimpleView( fv )); - detailedAction->setChecked( KFile::isDetailView( fv )); -} - -void KDirOperator::readConfig( TDEConfig *kc, const TQString& group ) -{ - if ( !kc ) - return; - TQString oldGroup = kc->group(); - if ( !group.isEmpty() ) - kc->setGroup( group ); - - defaultView = 0; - int sorting = 0; - - TQString viewStyle = kc->readEntry( TQString::fromLatin1("View Style"), - TQString::fromLatin1("Simple") ); - if ( viewStyle == TQString::fromLatin1("Detail") ) - defaultView |= KFile::Detail; - else - defaultView |= KFile::Simple; - if ( kc->readBoolEntry( TQString::fromLatin1("Separate Directories"), - DefaultMixDirsAndFiles ) ) - defaultView |= KFile::SeparateDirs; - if ( kc->readBoolEntry(TQString::fromLatin1("Show Preview"), false)) - defaultView |= KFile::PreviewContents; - - if ( kc->readBoolEntry( TQString::fromLatin1("Sort case insensitively"), - DefaultCaseInsensitive ) ) - sorting |= TQDir::IgnoreCase; - if ( kc->readBoolEntry( TQString::fromLatin1("Sort directories first"), - DefaultDirsFirst ) ) - sorting |= TQDir::DirsFirst; - - - TQString name = TQString::fromLatin1("Name"); - TQString sortBy = kc->readEntry( TQString::fromLatin1("Sort by"), name ); - if ( sortBy == name ) - sorting |= TQDir::Name; - else if ( sortBy == TQString::fromLatin1("Size") ) - sorting |= TQDir::Size; - else if ( sortBy == TQString::fromLatin1("Date") ) - sorting |= TQDir::Time; - - mySorting = static_cast( sorting ); - setSorting( mySorting ); - - - if ( kc->readBoolEntry( TQString::fromLatin1("Show hidden files"), - DefaultShowHidden ) ) { - showHiddenAction->setChecked( true ); - dir->setShowingDotFiles( true ); - } - if ( kc->readBoolEntry( TQString::fromLatin1("Sort reversed"), - DefaultSortReversed ) ) - reverseAction->setChecked( true ); - - kc->setGroup( oldGroup ); -} - -void KDirOperator::writeConfig( TDEConfig *kc, const TQString& group ) -{ - if ( !kc ) - return; - - const TQString oldGroup = kc->group(); - - if ( !group.isEmpty() ) - kc->setGroup( group ); - - TQString sortBy = TQString::fromLatin1("Name"); - if ( KFile::isSortBySize( mySorting ) ) - sortBy = TQString::fromLatin1("Size"); - else if ( KFile::isSortByDate( mySorting ) ) - sortBy = TQString::fromLatin1("Date"); - kc->writeEntry( TQString::fromLatin1("Sort by"), sortBy ); - - kc->writeEntry( TQString::fromLatin1("Sort reversed"), - reverseAction->isChecked() ); - kc->writeEntry( TQString::fromLatin1("Sort case insensitively"), - caseInsensitiveAction->isChecked() ); - kc->writeEntry( TQString::fromLatin1("Sort directories first"), - dirsFirstAction->isChecked() ); - - // don't save the separate dirs or preview when an application specific - // preview is in use. - bool appSpecificPreview = false; - if ( myPreview ) { - TQWidget *preview = const_cast( myPreview ); // grmbl - KFileMetaPreview *tmp = dynamic_cast( preview ); - appSpecificPreview = (tmp == 0L); - } - - if ( !appSpecificPreview ) { - if ( separateDirsAction->isEnabled() ) - kc->writeEntry( TQString::fromLatin1("Separate Directories"), - separateDirsAction->isChecked() ); - - TDEToggleAction *previewAction = static_cast(myActionCollection->action("preview")); - if ( previewAction->isEnabled() ) { - bool hasPreview = previewAction->isChecked(); - kc->writeEntry( TQString::fromLatin1("Show Preview"), hasPreview ); - } - } - - kc->writeEntry( TQString::fromLatin1("Show hidden files"), - showHiddenAction->isChecked() ); - - KFile::FileView fv = static_cast( m_viewKind ); - TQString style; - if ( KFile::isDetailView( fv ) ) - style = TQString::fromLatin1("Detail"); - else if ( KFile::isSimpleView( fv ) ) - style = TQString::fromLatin1("Simple"); - kc->writeEntry( TQString::fromLatin1("View Style"), style ); - - kc->setGroup( oldGroup ); -} - - -void KDirOperator::resizeEvent( TQResizeEvent * ) -{ - if (m_fileView) - m_fileView->widget()->resize( size() ); - - if ( TQT_BASE_OBJECT(progress->parent()) == TQT_BASE_OBJECT(this) ) // might be reparented into a statusbar - progress->move(2, height() - progress->height() -2); -} - -void KDirOperator::setOnlyDoubleClickSelectsFiles( bool enable ) -{ - d->onlyDoubleClickSelectsFiles = enable; - if ( m_fileView ) - m_fileView->setOnlyDoubleClickSelectsFiles( enable ); -} - -bool KDirOperator::onlyDoubleClickSelectsFiles() const -{ - return d->onlyDoubleClickSelectsFiles; -} - -void KDirOperator::slotStarted() -{ - progress->setProgress( 0 ); - // delay showing the progressbar for one second - d->progressDelayTimer->start( 1000, true ); -} - -void KDirOperator::slotShowProgress() -{ - progress->raise(); - progress->show(); - TQApplication::flushX(); -} - -void KDirOperator::slotProgress( int percent ) -{ - progress->setProgress( percent ); - // we have to redraw this as fast as possible - if ( progress->isVisible() ) - TQApplication::flushX(); -} - - -void KDirOperator::slotIOFinished() -{ - d->progressDelayTimer->stop(); - slotProgress( 100 ); - progress->hide(); - emit finishedLoading(); - resetCursor(); - - if ( m_fileView ) - m_fileView->listingCompleted(); -} - -void KDirOperator::slotCanceled() -{ - emit finishedLoading(); - resetCursor(); - - if ( m_fileView ) - m_fileView->listingCompleted(); -} - -KProgress * KDirOperator::progressBar() const -{ - return progress; -} - -void KDirOperator::clearHistory() -{ - backStack.clear(); - backAction->setEnabled( false ); - forwardStack.clear(); - forwardAction->setEnabled( false ); -} - -void KDirOperator::slotViewActionAdded( TDEAction *action ) -{ - if ( viewActionMenu->popupMenu()->count() == 5 ) // need to add a separator - viewActionMenu->insert( d->viewActionSeparator ); - - viewActionMenu->insert( action ); -} - -void KDirOperator::slotViewActionRemoved( TDEAction *action ) -{ - viewActionMenu->remove( action ); - - if ( viewActionMenu->popupMenu()->count() == 6 ) // remove the separator - viewActionMenu->remove( d->viewActionSeparator ); -} - -void KDirOperator::slotViewSortingChanged( TQDir::SortSpec sort ) -{ - mySorting = sort; - updateSortActions(); -} - -void KDirOperator::setEnableDirHighlighting( bool enable ) -{ - d->dirHighlighting = enable; -} - -bool KDirOperator::dirHighlighting() const -{ - return d->dirHighlighting; -} - -void KDirOperator::slotProperties() -{ - if ( m_fileView ) { - const KFileItemList *list = m_fileView->selectedItems(); - if ( !list->isEmpty() ) - (void) new KPropertiesDialog( *list, this, "props dlg", true); - } -} - -void KDirOperator::slotClearView() -{ - if ( m_fileView ) - m_fileView->clearView(); -} - -// ### temporary code -#include -bool KDirOperator::isReadable( const KURL& url ) -{ - if ( !url.isLocalFile() ) - return true; // what else can we say? - - KDE_struct_stat buf; - TQString ts = url.path(+1); - bool readable = ( KDE_stat( TQFile::encodeName( ts ), &buf) == 0 ); - if (readable) { // further checks - DIR *test; - test = opendir( TQFile::encodeName( ts )); // we do it just to test here - readable = (test != 0); - if (test) - closedir(test); - } - return readable; -} - -void KDirOperator::togglePreview( bool on ) -{ - if ( on ) - slotDefaultPreview(); - else - setView( (KFile::FileView) (m_viewKind & ~(KFile::PreviewContents|KFile::PreviewInfo)) ); -} - -void KDirOperator::slotRefreshItems( const KFileItemList& items ) -{ - if ( !m_fileView ) - return; - - KFileItemListIterator it( items ); - for ( ; it.current(); ++it ) - m_fileView->updateView( it.current() ); -} - -void KDirOperator::setViewConfig( TDEConfig *config, const TQString& group ) -{ - d->config = config; - d->configGroup = group; -} - -TDEConfig * KDirOperator::viewConfig() -{ - return d->config; -} - -TQString KDirOperator::viewConfigGroup() const -{ - return d->configGroup; -} - -void KDirOperator::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "tdediroperator.moc" diff --git a/tdeio/tdefile/kdiroperator.h b/tdeio/tdefile/kdiroperator.h deleted file mode 100644 index 95bf5c5ba..000000000 --- a/tdeio/tdefile/kdiroperator.h +++ /dev/null @@ -1,950 +0,0 @@ -// -*- c++ -*- -/* This file is part of the KDE libraries - Copyright (C) 1999 Stephan Kulow - 2000,2001 Carsten Pfeiffer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef KDIROPERATOR_H_ -#define KDIROPERATOR_H_ - -#include -#include - -#include -#include -#include -#include -#include -#include - -class TQPopupMenu; -class TQTimer; - -class TDEAction; -class KDirLister; -class TDEToggleAction; -class TDEActionSeparator; -class TDEActionMenu; -class TQWidgetStack; -class KProgress; -namespace TDEIO { - class CopyJob; - class DeleteJob; -} - -/** - * This widget works as a network transparent filebrowser. You specify a URL - * to display and this url will be loaded via KDirLister. The user can - * browse through directories, highlight and select files, delete or rename - * files. - * - * It supports different views, e.g. a detailed view (see KFileDetailView), - * a simple icon view (see KFileIconView), a combination of two views, - * separating directories and files ( KCombiView). - * - * Additionally, a preview view is available (see KFilePreview), which can - * show either a simple or detailed view and additionally a preview widget - * (see setPreviewWidget()). KImageFilePreview is one implementation - * of a preview widget, that displays previews for all supported filetypes - * utilizing TDEIO::PreviewJob. - * - * Currently, those classes don't support Drag&Drop out of the box -- there - * you have to use your own view-classes. You can use some DnD-aware views - * from Bj�n Sahlstr� until they will be integrated - * into this library. See http://devel-home.kde.org/~pfeiffer/DnD-classes.tar.gz - * - * This widget is the one used in the KFileDialog. - * - * Basic usage is like this: - * \code - * KDirOperator *op = new KDirOperator( KURL( "file:/home/gis" ), this ); - * // some signals you might be interested in - * connect(op, TQT_SIGNAL(urlEntered(const KURL&)), - * TQT_SLOT(urlEntered(const KURL&))); - * connect(op, TQT_SIGNAL(fileHighlighted(const KFileItem *)), - * TQT_SLOT(fileHighlighted(const KFileItem *))); - * connect(op, TQT_SIGNAL(fileSelected(const KFileItem *)), - * TQT_SLOT(fileSelected(const KFileItem *))); - * connect(op, TQT_SIGNAL(finishedLoading()), - * TQT_SLOT(slotLoadingFinished())); - * - * op->readConfig( TDEGlobal::config(), "Your KDiroperator ConfigGroup" ); - * op->setView(KFile::Default); - * \endcode - * - * This will create a childwidget of 'this' showing the directory contents - * of /home/gis in the default-view. The view is determined by the readConfig() - * call, which will read the KDirOperator settings, the user left your program - * with (and which you saved with op->writeConfig()). - * - * @short A widget for displaying files and browsing directories. - * @author Stephan Kulow , Carsten Pfeiffer - */ -class TDEIO_EXPORT KDirOperator : public TQWidget -{ - Q_OBJECT - - public: - /** - * The various action types. These values can be or'd together - * @since 3.1 - */ - enum ActionTypes { SortActions = 1, - ViewActions = 2, - NavActions = 4, - FileActions = 8, - AllActions = 15 }; - /** - * Constructs the KDirOperator with no initial view. As the views are - * configurable, call readConfig() to load the user's configuration - * and then setView to explicitly set a view. - * - * This constructor doesn't start loading the url, setView will do it. - */ - KDirOperator(const KURL& urlName = KURL(), - TQWidget *parent = 0, const char* name = 0); - /** - * Destroys the KDirOperator. - */ - virtual ~KDirOperator(); - - /** - * Enables/disables showing hidden files. - */ - // ### KDE4: make virtual - void setShowHiddenFiles ( bool s ) { showHiddenAction->setChecked( s ); } - - /** - * @returns true when hidden files are shown or false otherwise. - */ - bool showHiddenFiles () const { return showHiddenAction->isChecked(); } - - /** - * Stops loading immediately. You don't need to call this, usually. - */ - void close(); - /// Reimplemented to avoid "hidden virtual" warnings - virtual bool close( bool alsoDelete ) { return TQWidget::close( alsoDelete ); } - - /** - * Sets a filter like "*.cpp *.h *.o". Only files matching that filter - * will be shown. Call updateDir() to apply it. - * - * @see KDirLister::setNameFilter - * @see nameFilter - */ - void setNameFilter(const TQString& filter); - - /** - * @returns the current namefilter. - * @see setNameFilter - */ - const TQString& nameFilter() const { return dir->nameFilter(); } - - /** - * Sets a list of mimetypes as filter. Only files of those mimetypes - * will be shown. - * - * Example: - * \code - * TQStringList filter; - * filter << "text/html" << "image/png" << "inode/directory"; - * dirOperator->setMimefilter( filter ); - * \endcode - * - * Node: Without the mimetype inode/directory, only files would be shown. - * Call updateDir() to apply it. - * - * @see KDirLister::setMimeFilter - * @see mimeFilter - */ - void setMimeFilter( const TQStringList& mimetypes ); - - /** - * @returns the current mime filter. - */ - TQStringList mimeFilter() const { return dir->mimeFilters(); } - - /** - * Clears both the namefilter and mimetype filter, so that all files and - * directories will be shown. Call updateDir() to apply it. - * - * @see setMimeFilter - * @see setNameFilter - */ - void clearFilter(); - - /** - * @returns the current url - */ - KURL url() const; - - /** - * Sets a new url to list. - * @param clearforward specifies whether the "forward" history should be cleared. - * @param url the URL to set - */ - // ### KDE4: make virtual - void setURL(const KURL& url, bool clearforward); - - /** - * Clears the current selection and attempts to set @p filename - * the current file. filename is just the name, no path or url. - */ - void setCurrentItem( const TQString& filename ); - - /** - * Sets a new KFileView to be used for showing and browsing files. - * Note: this will read the current url() to fill the view. - * - * @see KFileView - * @see KFileIconView - * @see KFileDetailView - * @see KCombiView - * @see view - */ - // ### KDE4: make virtual - void setView(KFileView *view); - - /** - * @returns the currently used view. - * @see setView - */ - KFileView * view() const { return m_fileView; } - - /** - * Returns the widget of the current view. 0L if there is no view/widget. - * (KFileView itself is not a widget.) - */ - TQWidget * viewWidget() const { return m_fileView ? m_fileView->widget() : 0L; } - - /** - * Sets one of the predefined fileviews - * @see KFile::FileView - */ - // ### KDE4: make virtual - void setView(KFile::FileView view); - - /** - * Sets the way to sort files and directories. - */ - void setSorting( TQDir::SortSpec ); - - /** - * @returns the current way of sorting files and directories - */ - TQDir::SortSpec sorting() const { return mySorting; } - - /** - * @returns true if we are displaying the root directory of the current url - */ - bool isRoot() const { return url().path() == TQChar('/'); } - - /** - * @returns the object listing the directory - */ - KDirLister *dirLister() const { return dir; } - - /** - * @returns the progress widget, that is shown during directory listing. - * You can for example reparent() it to put it into a statusbar. - */ - KProgress * progressBar() const; - - /** - * Sets the listing/selection mode for the views, an OR'ed combination of - * @li File - * @li Directory - * @li Files - * @li ExistingOnly - * @li LocalOnly - * - * You cannot mix File and Files of course, as the former means - * single-selection mode, the latter multi-selection. - */ - // ### KDE4: make virtual - void setMode( KFile::Mode m ); - /** - * @returns the listing/selection mode. - */ - KFile::Mode mode() const; - - /** - * Sets a preview-widget to be shown next to the file-view. - * The ownership of @p w is transferred to KDirOperator, so don't - * delete it yourself! - */ - // ### KDE4: make virtual - void setPreviewWidget(const TQWidget *w); - - /** - * @returns a list of all currently selected items. If there is no view, - * then 0L is returned. - */ - const KFileItemList * selectedItems() const { - return ( m_fileView ? m_fileView->selectedItems() : 0L ); - } - - /** - * @returns true if @p item is currently selected, or false otherwise. - */ - inline bool isSelected( const KFileItem *item ) const { - return ( m_fileView ? m_fileView->isSelected( item ) : false ); - } - - /** - * @returns the number of directories in the currently listed url. - * Returns 0 if there is no view. - */ - int numDirs() const; - - /** - * @returns the number of files in the currently listed url. - * Returns 0 if there is no view. - */ - int numFiles() const; - - /** - * @returns a TDECompletion object, containing all filenames and - * directories of the current directory/URL. - * You can use it to insert it into a KLineEdit or KComboBox - * Note: it will only contain files, after prepareCompletionObjects() - * has been called. It will be implicitly called from makeCompletion() - * or makeDirCompletion() - */ - TDECompletion * completionObject() const { - return const_cast( &myCompletion ); - } - - /** - * @returns a TDECompletion object, containing only all directories of the - * current directory/URL. - * You can use it to insert it into a KLineEdit or KComboBox - * Note: it will only contain directories, after - * prepareCompletionObjects() has been called. It will be implicitly - * called from makeCompletion() or makeDirCompletion() - */ - TDECompletion *dirCompletionObject() const { - return const_cast( &myDirCompletion ); - } - - /** - * an accessor to a collection of all available Actions. The actions - * are static, they will be there all the time (no need to connect to - * the signals TDEActionCollection::inserted() or removed(). - * - * There are the following actions: - * - * @li popupMenu : an ActionMenu presenting a popupmenu with all actions - * @li up : changes to the parent directory - * @li back : goes back to the previous directory - * @li forward : goes forward in the history - * @li home : changes to the user's home directory - * @li reload : reloads the current directory - * @li separator : a separator - * @li mkdir : opens a dialog box to create a directory - * @li delete : deletes the selected files/directories - * @li sorting menu : an ActionMenu containing all sort-options - * @li by name : sorts by name - * @li by date : sorts by date - * @li by size : sorts by size - * @li reversed : reverses the sort order - * @li dirs first : sorts directories before files - * @li case insensitive : sorts case insensitively - * @li view menu : an ActionMenu containing all actions concerning the view - * @li short view : shows a simple fileview - * @li detailed view : shows a detailed fileview (dates, permissions ,...) - * @li show hidden : shows hidden files - * @li separate dirs : shows directories in a separate pane - * @li preview : shows a preview next to the fileview - * @li single : hides the separate view for directories or the preview - * @li properties : shows a KPropertiesDialog for the selected files - * - * The short and detailed view are in an exclusive group. The sort-by - * actions are in an exclusive group as well. Also the "separate dirs", - * "preview" and "single" actions are in an exclusive group. - * - * You can e.g. use - * \code - * actionCollection()->action( "up" )->plug( someToolBar ); - * \endcode - * to add a button into a toolbar, which makes the dirOperator change to - * its parent directory. - * - * @returns all available Actions - */ - TDEActionCollection * actionCollection() const { return myActionCollection; } - - /** - * Sets the config object and the to be used group in KDirOperator. This - * will be used to store the view's configuration via - * KFileView::writeConfig() (and for KFileView::readConfig()). - * If you don't set this, the views cannot save and restore their - * configuration. - * - * Usually you call this right after KDirOperator creation so that the view - * instantiation can make use of it already. - * - * Note that KDirOperator does NOT take ownership of that object (typically - * it's TDEGlobal::config() anyway. - * - * @see viewConfig - * @see viewConfigGroup - * @since 3.1 - */ - // ### KDE4: make virtual - void setViewConfig( TDEConfig *config, const TQString& group ); - - /** - * Returns the TDEConfig object used for saving and restoring view's - * configuration. - * @returns the TDEConfig object used for saving and restoring view's - * configuration. - * @since 3.1 - */ - TDEConfig *viewConfig(); - - /** - * Returns the group name used for saving and restoring view's - * configuration. - * @returns the group name used for saving and restoring view's - * configuration. - * @since 3.1 - */ - TQString viewConfigGroup() const; - - /** - * Reads the default settings for a view, i.e. the default KFile::FileView. - * Also reads the sorting and whether hidden files should be shown. - * Note: the default view will not be set - you have to call - * \code - * setView( KFile::Default ) - * \endcode - * to apply it. - * - * @see setView - * @see setViewConfig - * @see writeConfig - */ - virtual void readConfig( TDEConfig *, const TQString& group = TQString::null ); - - /** - * Saves the current settings like sorting, simple or detailed view. - * - * @see readConfig - * @see setViewConfig - */ - virtual void writeConfig( TDEConfig *, const TQString& group = TQString::null ); - - - /** - * This is a KFileDialog specific hack: we want to select directories with - * single click, but not files. But as a generic class, we have to be able - * to select files on single click as well. - * - * This gives us the opportunity to do both. - * - * The default is false, set it to true if you don't want files selected - * with single click. - */ - void setOnlyDoubleClickSelectsFiles( bool enable ); - - /** - * @returns whether files (not directories) should only be select()ed by - * double-clicks. - * @see setOnlyDoubleClickSelectsFiles - */ - bool onlyDoubleClickSelectsFiles() const; - - /** - * Creates the given directory/url. If it is a relative path, - * it will be completed with the current directory. - * If enterDirectory is true, the directory will be entered after a - * successful operation. If unsuccessful, a messagebox will be presented - * to the user. - * @returns true if the directory could be created. - */ - // ### KDE4: make virtual and turn TQString into KURL - bool mkdir( const TQString& directory, bool enterDirectory = true ); - - /** - * Starts and returns a TDEIO::DeleteJob to delete the given @p items. - * - * @param items the list of items to be deleted - * @param ask specifies whether a confirmation dialog should be shown - * @param showProgress passed to the DeleteJob to show a progress dialog - */ - // ### KDE4: make virtual - TDEIO::DeleteJob * del( const KFileItemList& items, - bool ask = true, bool showProgress = true ); - - /** - * Starts and returns a TDEIO::DeleteJob to delete the given @p items. - * - * @param items the list of items to be deleted - * @param parent the parent widget used for the confirmation dialog - * @param ask specifies whether a confirmation dialog should be shown - * @param showProgress passed to the DeleteJob to show a progress dialog - * @since 3.1 - */ - // ### KDE4: make virtual - TDEIO::DeleteJob * del( const KFileItemList& items, TQWidget *parent, - bool ask = true, bool showProgress = true ); - - /** - * Clears the forward and backward history. - */ - void clearHistory(); - - /** - * When going up in the directory hierarchy, KDirOperator can highlight - * the directory that was just left. - * - * I.e. when you go from /home/gis/src to /home/gis, the item "src" will - * be made the current item. - * - * Default is off, because this behavior introduces bug #136630. - * Don't enable until this bug is fixed. - */ - // ### KDE4: make virtual - void setEnableDirHighlighting( bool enable ); - - /** - * @returns whether the last directory will be made the current item - * when going up in the directory hierarchy. - * - * Default is false. - */ - bool dirHighlighting() const; - - /** - * @returns true if we are in directory-only mode, that is, no files are - * shown. - */ - bool dirOnlyMode() const { return dirOnlyMode( myMode ); } - - static bool dirOnlyMode( uint mode ) { - return ( (mode & KFile::Directory) && - (mode & (KFile::File | KFile::Files)) == 0 ); - } - - /** - * Sets up the action menu. - * @param whichActions is an value of OR'd ActionTypes that controls which actions to show in the action menu - */ - void setupMenu(int whichActions); - - /** - * Reimplemented - allow dropping of files if @p b is true - * @param b true if the widget should allow dropping of files - */ - virtual void setAcceptDrops(bool b); - - /** - * Sets the options for dropping files. - * @see KFileView::DropOptions - * @since 3.2 - */ - // ### KDE4: make virtual - void setDropOptions(int options); - - /** - * Starts and returns a TDEIO::CopyJob to trash the given @p items. - * - * @param items the list of items to be trashed - * @param parent the parent widget used for the confirmation dialog - * @param ask specifies whether a confirmation dialog should be shown - * @param showProgress passed to the CopyJob to show a progress dialog - * @since 3.4 - */ - // ### KDE4: make virtual - TDEIO::CopyJob * trash( const KFileItemList& items, TQWidget *parent, - bool ask = true, bool showProgress = true ); - -protected: - /** - * A view factory for creating predefined fileviews. Called internally by setView - * , but you can also call it directly. Reimplement this if you depend on self defined fileviews. - * @param parent is the TQWidget to be set as parent - * @param view is the predefined view to be set, note: this can be several ones OR:ed together. - * @returns the created KFileView - * @see KFileView - * @see KCombiView - * @see KFileDetailView - * @see KFileIconView - * @see KFilePreview - * @see KFile::FileView - * @see setView - */ - virtual KFileView* createView( TQWidget* parent, KFile::FileView view ); - /** - * Sets a custom KDirLister to list directories. - */ - // ### KDE4: make virtual - void setDirLister( KDirLister *lister ); - - virtual void resizeEvent( TQResizeEvent * ); - - /** - * Sets up all the actions. Called from the constructor, you usually - * better not call this. - */ - void setupActions(); - - /** - * Updates the sorting-related actions to comply with the current sorting - * @see sorting - */ - void updateSortActions(); - - /** - * Updates the view-related actions to comply with the current - * KFile::FileView - */ - void updateViewActions(); - - /** - * Sets up the context-menu with all the necessary actions. Called from the - * constructor, you usually don't need to call this. - * @since 3.1 - */ - void setupMenu(); - - /** - * Synchronizes the completion objects with the entries of the - * currently listed url. - * - * Automatically called from makeCompletion() and - * makeDirCompletion() - */ - void prepareCompletionObjects(); - - /** - * Checks if there support from TDEIO::PreviewJob for the currently - * shown files, taking mimeFilter() and nameFilter() into account - * Enables/disables the preview-action accordingly. - */ - bool checkPreviewSupport(); - -public slots: - /** - * Goes one step back in the history and opens that url. - */ - // ### KDE4: make virtual - void back(); - - /** - * Goes one step forward in the history and opens that url. - */ - // ### KDE4: make virtual - void forward(); - - /** - * Enters the home directory. - */ - // ### KDE4: make virtual - void home(); - - /** - * Goes one directory up from the current url. - */ - // ### KDE4: make virtual - void cdUp(); - - /** - * to update the view after changing the settings - */ - void updateDir(); - - /** - * Re-reads the current url. - */ - // ### KDE4: make virtual - void rereadDir(); - - /** - * Opens a dialog to create a new directory. - */ - // ### KDE4: make virtual - void mkdir(); - - /** - * Deletes the currently selected files/directories. - */ - // ### KDE4: make virtual - void deleteSelected(); - - /** - * Enables/disables actions that are selection dependent. Call this e.g. - * when you are about to show a popup menu using some of KDirOperators - * actions. - */ - void updateSelectionDependentActions(); - - /** - * Tries to complete the given string (only completes files). - */ - TQString makeCompletion(const TQString&); - - /** - * Tries to complete the given string (only completes directores). - */ - TQString makeDirCompletion(const TQString&); - - /** - * Trashes the currently selected files/directories. - * @since 3.4 - */ - // ### KDE4: make virtual - void trashSelected(TDEAction::ActivationReason, TQt::ButtonState); - -protected slots: - /** - * Restores the normal cursor after showing the busy-cursor. Also hides - * the progressbar. - */ - void resetCursor(); - - /** - * Called after setURL() to load the directory, update the history, - * etc. - */ - void pathChanged(); - - /** - * Adds a new list of KFileItems to the view - * (coming from KDirLister) - */ - void insertNewFiles(const KFileItemList &newone); - - /** - * Removes the given KFileItem item from the view (usually called from - * KDirLister). - */ - void itemDeleted(KFileItem *); - - /** - * Enters the directory specified by the given @p item. - */ - // ### KDE4: make virtual - void selectDir(const KFileItem *item ); - - /** - * Emits fileSelected( item ) - */ - void selectFile(const KFileItem *item); - - /** - * Emits fileHighlighted( i ) - */ - void highlightFile(const KFileItem* i) { emit fileHighlighted( i ); } - - /** - * Called upon right-click to activate the popupmenu. - */ - virtual void activatedMenu( const KFileItem *, const TQPoint& pos ); - - /** - * Changes sorting to sort by name - */ - void sortByName() { byNameAction->setChecked( true ); } - - /** - * Changes sorting to sort by size - */ - void sortBySize() { bySizeAction->setChecked( true ); } - - /** - * Changes sorting to sort by date - */ - void sortByDate() { byDateAction->setChecked( true ); } - - /** - * Changes sorting to reverse sorting - */ - void sortReversed() { reverseAction->setChecked( !reverseAction->isChecked() ); } - - /** - * Toggles showing directories first / having them sorted like files. - */ - void toggleDirsFirst() { dirsFirstAction->setChecked( !dirsFirstAction->isChecked() ); } - - /** - * Toggles case sensitive / case insensitive sorting - */ - void toggleIgnoreCase() { caseInsensitiveAction->setChecked( !caseInsensitiveAction->isChecked() ); } - - /** - * Tries to make the given @p match as current item in the view and emits - * completion( match ) - */ - void slotCompletionMatch(const TQString& match); - -signals: - void urlEntered(const KURL& ); - void updateInformation(int files, int dirs); - void completion(const TQString&); - void finishedLoading(); - - /** - * Emitted whenever the current fileview is changed, either by an explicit - * call to setView() or by the user selecting a different view thru - * the GUI. - */ - void viewChanged( KFileView * newView ); - - /** - * Emitted when a file is highlighted or generally the selection changes in - * multiselection mode. In the latter case, @p item is 0L. You can access - * the selected items with selectedItems(). - */ - void fileHighlighted( const KFileItem *item ); - void dirActivated( const KFileItem *item ); - void fileSelected( const KFileItem *item ); - /** - * Emitted when files are dropped. Dropping files is disabled by - * default. You need to enable it with setAcceptDrops() - * @param item the item on which the drop occurred or 0. - * @param event the drop event itself. - * @param urls the urls that where dropped. - * @since 3.2 - */ - void dropped(const KFileItem *item, TQDropEvent*event, const KURL::List&urls); -private: - /** - * Contains all URLs you can reach with the back button. - */ - TQPtrStack backStack; - - /** - * Contains all URLs you can reach with the forward button. - */ - TQPtrStack forwardStack; - - KDirLister *dir; - KURL currUrl; - - TDECompletion myCompletion; - TDECompletion myDirCompletion; - bool myCompleteListDirty; - TQDir::SortSpec mySorting; - - /** - * Checks whether we preview support is available for the current - * mimetype/namefilter - */ - bool checkPreviewInternal() const; - - /** - * takes action on the new location. If it's a directory, change - * into it, if it's a file, correct the name, etc. - */ - void checkPath(const TQString& txt, bool takeFiles = false); - - void connectView(KFileView *); - - bool openURL( const KURL& url, bool keep = false, bool reload = false ); - - KFileView *m_fileView; - KFileItemList pendingMimeTypes; - - // the enum KFile::FileView as an int - int m_viewKind; - int defaultView; - - KFile::Mode myMode; - KProgress *progress; - - const TQWidget *myPreview; // temporary pointer for the preview widget - - // actions for the popupmenus - // ### clean up all those -- we have them all in the actionMenu! - TDEActionMenu *actionMenu; - - TDEAction *backAction; - TDEAction *forwardAction; - TDEAction *homeAction; - TDEAction *upAction; - TDEAction *reloadAction; - TDEActionSeparator *actionSeparator; - TDEAction *mkdirAction; - - TDEActionMenu *sortActionMenu; - TDERadioAction *byNameAction; - TDERadioAction *byDateAction; - TDERadioAction *bySizeAction; - TDEToggleAction *reverseAction; - TDEToggleAction *dirsFirstAction; - TDEToggleAction *caseInsensitiveAction; - - TDEActionMenu *viewActionMenu; - TDERadioAction *shortAction; - TDERadioAction *detailedAction; - TDEToggleAction *showHiddenAction; - TDEToggleAction *separateDirsAction; - - TDEActionCollection *myActionCollection; - TDEActionCollection *viewActionCollection; - -private slots: - /** - * @internal - */ - void slotDetailedView(); - void slotSimpleView(); - void slotToggleHidden( bool ); - - void slotSeparateDirs(); - void slotDefaultPreview(); - void togglePreview( bool ); - - void slotSortByName(); - void slotSortBySize(); - void slotSortByDate(); - void slotSortReversed(); - void slotToggleDirsFirst(); - void slotToggleIgnoreCase(); - - void slotStarted(); - void slotProgress( int ); - void slotShowProgress(); - void slotIOFinished(); - void slotCanceled(); - void slotRedirected( const KURL& ); - - void slotViewActionAdded( TDEAction * ); - void slotViewActionRemoved( TDEAction * ); - void slotViewSortingChanged( TQDir::SortSpec ); - - void slotClearView(); - void slotRefreshItems( const KFileItemList& items ); - - void slotProperties(); - - void insertViewDependentActions(); - -private: - static bool isReadable( const KURL& url ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - class KDirOperatorPrivate; - KDirOperatorPrivate *d; -}; - -#endif diff --git a/tdeio/tdefile/tdediroperator.cpp b/tdeio/tdefile/tdediroperator.cpp new file mode 100644 index 000000000..dc44aa8ba --- /dev/null +++ b/tdeio/tdefile/tdediroperator.cpp @@ -0,0 +1,1740 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999,2000 Stephan Kulow + 1999,2000,2001,2002,2003 Carsten Pfeiffer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config-tdefile.h" +#include "kcombiview.h" +#include "tdediroperator.h" +#include "tdefiledetailview.h" +#include "tdefileiconview.h" +#include "tdefilepreview.h" +#include "tdefileview.h" +#include "tdefileitem.h" +#include "tdefilemetapreview.h" + + +template class TQPtrStack; +template class TQDict; + + +class KDirOperator::KDirOperatorPrivate +{ +public: + KDirOperatorPrivate() { + onlyDoubleClickSelectsFiles = false; + progressDelayTimer = 0L; + dirHighlighting = false; + config = 0L; + dropOptions = 0; + } + + ~KDirOperatorPrivate() { + delete progressDelayTimer; + } + + bool dirHighlighting; + TQString lastURL; // used for highlighting a directory on cdUp + bool onlyDoubleClickSelectsFiles; + TQTimer *progressDelayTimer; + TDEActionSeparator *viewActionSeparator; + int dropOptions; + + TDEConfig *config; + TQString configGroup; +}; + +KDirOperator::KDirOperator(const KURL& _url, + TQWidget *parent, const char* _name) + : TQWidget(parent, _name), + dir(0), + m_fileView(0), + progress(0) +{ + myPreview = 0L; + myMode = KFile::File; + m_viewKind = KFile::Simple; + mySorting = static_cast(TQDir::Name | TQDir::DirsFirst); + d = new KDirOperatorPrivate; + + if (_url.isEmpty()) { // no dir specified -> current dir + TQString strPath = TQDir::currentDirPath(); + strPath.append('/'); + currUrl = KURL(); + currUrl.setProtocol(TQString::fromLatin1("file")); + currUrl.setPath(strPath); + } + else { + currUrl = _url; + if ( currUrl.protocol().isEmpty() ) + currUrl.setProtocol(TQString::fromLatin1("file")); + + currUrl.addPath("/"); // make sure we have a trailing slash! + } + + setDirLister( new KDirLister( true ) ); + + connect(&myCompletion, TQT_SIGNAL(match(const TQString&)), + TQT_SLOT(slotCompletionMatch(const TQString&))); + + progress = new KProgress(this, "progress"); + progress->adjustSize(); + progress->move(2, height() - progress->height() -2); + + d->progressDelayTimer = new TQTimer( this, "progress delay timer" ); + connect( d->progressDelayTimer, TQT_SIGNAL( timeout() ), + TQT_SLOT( slotShowProgress() )); + + myCompleteListDirty = false; + + backStack.setAutoDelete( true ); + forwardStack.setAutoDelete( true ); + + // action stuff + setupActions(); + setupMenu(); + + setFocusPolicy(TQ_WheelFocus); +} + +KDirOperator::~KDirOperator() +{ + resetCursor(); + if ( m_fileView ) + { + if ( d->config ) + m_fileView->writeConfig( d->config, d->configGroup ); + + delete m_fileView; + m_fileView = 0L; + } + + delete myPreview; + delete dir; + delete d; +} + + +void KDirOperator::setSorting( TQDir::SortSpec spec ) +{ + if ( m_fileView ) + m_fileView->setSorting( spec ); + mySorting = spec; + updateSortActions(); +} + +void KDirOperator::resetCursor() +{ + TQApplication::restoreOverrideCursor(); + progress->hide(); +} + +void KDirOperator::insertViewDependentActions() +{ + // If we have a new view actionCollection(), insert its actions + // into viewActionMenu. + + if( !m_fileView ) + return; + + if ( (viewActionMenu->popupMenu()->count() == 0) || // Not yet initialized or... + (viewActionCollection != m_fileView->actionCollection()) ) // ...changed since. + { + if (viewActionCollection) + { + disconnect( viewActionCollection, TQT_SIGNAL( inserted( TDEAction * )), + this, TQT_SLOT( slotViewActionAdded( TDEAction * ))); + disconnect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )), + this, TQT_SLOT( slotViewActionRemoved( TDEAction * ))); + } + + viewActionMenu->popupMenu()->clear(); +// viewActionMenu->insert( shortAction ); +// viewActionMenu->insert( detailedAction ); +// viewActionMenu->insert( actionSeparator ); + viewActionMenu->insert( myActionCollection->action( "short view" ) ); + viewActionMenu->insert( myActionCollection->action( "detailed view" ) ); + viewActionMenu->insert( actionSeparator ); + viewActionMenu->insert( showHiddenAction ); +// viewActionMenu->insert( myActionCollection->action( "single" )); + viewActionMenu->insert( separateDirsAction ); + // Warning: adjust slotViewActionAdded() and slotViewActionRemoved() + // when you add/remove actions here! + + viewActionCollection = m_fileView->actionCollection(); + if (!viewActionCollection) + return; + + if ( !viewActionCollection->isEmpty() ) + { + viewActionMenu->insert( d->viewActionSeparator ); + + // first insert the normal actions, then the grouped ones + TQStringList groups = viewActionCollection->groups(); + groups.prepend( TQString::null ); // actions without group + TQStringList::ConstIterator git = groups.begin(); + TDEActionPtrList list; + TDEAction *sep = actionCollection()->action("separator"); + for ( ; git != groups.end(); ++git ) + { + if ( git != groups.begin() ) + viewActionMenu->insert( sep ); + + list = viewActionCollection->actions( *git ); + TDEActionPtrList::ConstIterator it = list.begin(); + for ( ; it != list.end(); ++it ) + viewActionMenu->insert( *it ); + } + } + + connect( viewActionCollection, TQT_SIGNAL( inserted( TDEAction * )), + TQT_SLOT( slotViewActionAdded( TDEAction * ))); + connect( viewActionCollection, TQT_SIGNAL( removed( TDEAction * )), + TQT_SLOT( slotViewActionRemoved( TDEAction * ))); + } +} + +void KDirOperator::activatedMenu( const KFileItem *, const TQPoint& pos ) +{ + setupMenu(); + updateSelectionDependentActions(); + + actionMenu->popup( pos ); +} + +void KDirOperator::updateSelectionDependentActions() +{ + bool hasSelection = m_fileView && m_fileView->selectedItems() && + !m_fileView->selectedItems()->isEmpty(); + myActionCollection->action( "trash" )->setEnabled( hasSelection ); + myActionCollection->action( "delete" )->setEnabled( hasSelection ); + myActionCollection->action( "properties" )->setEnabled( hasSelection ); +} + +void KDirOperator::setPreviewWidget(const TQWidget *w) +{ + if(w != 0L) + m_viewKind = (m_viewKind | KFile::PreviewContents); + else + m_viewKind = (m_viewKind & ~KFile::PreviewContents); + + delete myPreview; + myPreview = w; + + TDEToggleAction *preview = static_cast(myActionCollection->action("preview")); + preview->setEnabled( w != 0L ); + preview->setChecked( w != 0L ); + setView( static_cast(m_viewKind) ); +} + +int KDirOperator::numDirs() const +{ + return m_fileView ? m_fileView->numDirs() : 0; +} + +int KDirOperator::numFiles() const +{ + return m_fileView ? m_fileView->numFiles() : 0; +} + +void KDirOperator::slotDetailedView() +{ + KFile::FileView view = static_cast( (m_viewKind & ~KFile::Simple) | KFile::Detail ); + setView( view ); +} + +void KDirOperator::slotSimpleView() +{ + KFile::FileView view = static_cast( (m_viewKind & ~KFile::Detail) | KFile::Simple ); + setView( view ); +} + +void KDirOperator::slotToggleHidden( bool show ) +{ + dir->setShowingDotFiles( show ); + updateDir(); + if ( m_fileView ) + m_fileView->listingCompleted(); +} + +void KDirOperator::slotSeparateDirs() +{ + if (separateDirsAction->isChecked()) + { + KFile::FileView view = static_cast( m_viewKind | KFile::SeparateDirs ); + setView( view ); + } + else + { + KFile::FileView view = static_cast( m_viewKind & ~KFile::SeparateDirs ); + setView( view ); + } +} + +void KDirOperator::slotDefaultPreview() +{ + m_viewKind = m_viewKind | KFile::PreviewContents; + if ( !myPreview ) { + myPreview = new KFileMetaPreview( this ); + (static_cast( myActionCollection->action("preview") ))->setChecked(true); + } + + setView( static_cast(m_viewKind) ); +} + +void KDirOperator::slotSortByName() +{ + int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask; + m_fileView->setSorting( static_cast( sorting | TQDir::Name )); + mySorting = m_fileView->sorting(); + caseInsensitiveAction->setEnabled( true ); +} + +void KDirOperator::slotSortBySize() +{ + int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask; + m_fileView->setSorting( static_cast( sorting | TQDir::Size )); + mySorting = m_fileView->sorting(); + caseInsensitiveAction->setEnabled( false ); +} + +void KDirOperator::slotSortByDate() +{ + int sorting = (m_fileView->sorting()) & ~TQDir::SortByMask; + m_fileView->setSorting( static_cast( sorting | TQDir::Time )); + mySorting = m_fileView->sorting(); + caseInsensitiveAction->setEnabled( false ); +} + +void KDirOperator::slotSortReversed() +{ + if ( m_fileView ) + m_fileView->sortReversed(); +} + +void KDirOperator::slotToggleDirsFirst() +{ + TQDir::SortSpec sorting = m_fileView->sorting(); + if ( !KFile::isSortDirsFirst( sorting ) ) + m_fileView->setSorting( static_cast( sorting | TQDir::DirsFirst )); + else + m_fileView->setSorting( static_cast( sorting & ~TQDir::DirsFirst)); + mySorting = m_fileView->sorting(); +} + +void KDirOperator::slotToggleIgnoreCase() +{ + TQDir::SortSpec sorting = m_fileView->sorting(); + if ( !KFile::isSortCaseInsensitive( sorting ) ) + m_fileView->setSorting( static_cast( sorting | TQDir::IgnoreCase )); + else + m_fileView->setSorting( static_cast( sorting & ~TQDir::IgnoreCase)); + mySorting = m_fileView->sorting(); +} + +void KDirOperator::mkdir() +{ + bool ok; + TQString where = url().pathOrURL(); + TQString name = i18n( "New Folder" ); + if ( url().isLocalFile() && TQFileInfo( url().path(+1) + name ).exists() ) + name = TDEIO::RenameDlg::suggestName( url(), name ); + + TQString dir = KInputDialog::getText( i18n( "New Folder" ), + i18n( "Create new folder in:\n%1" ).arg( where ), + name, &ok, this); + if (ok) + mkdir( TDEIO::encodeFileName( dir ), true ); +} + +bool KDirOperator::mkdir( const TQString& directory, bool enterDirectory ) +{ + // Creates "directory", relative to the current directory (currUrl). + // The given path may contain any number directories, existant or not. + // They will all be created, if possible. + + bool writeOk = false; + bool exists = false; + KURL url( currUrl ); + + TQStringList dirs = TQStringList::split( TQDir::separator(), directory ); + TQStringList::ConstIterator it = dirs.begin(); + + for ( ; it != dirs.end(); ++it ) + { + url.addPath( *it ); + exists = TDEIO::NetAccess::exists( url, false, 0 ); + writeOk = !exists && TDEIO::NetAccess::mkdir( url, topLevelWidget() ); + } + + if ( exists ) // url was already existant + { + KMessageBox::sorry(viewWidget(), i18n("A file or folder named %1 already exists.").arg(url.pathOrURL())); + enterDirectory = false; + } + else if ( !writeOk ) { + KMessageBox::sorry(viewWidget(), i18n("You do not have permission to " + "create that folder." )); + } + else if ( enterDirectory ) { + setURL( url, true ); + } + + return writeOk; +} + +TDEIO::DeleteJob * KDirOperator::del( const KFileItemList& items, + bool ask, bool showProgress ) +{ + return del( items, this, ask, showProgress ); +} + +TDEIO::DeleteJob * KDirOperator::del( const KFileItemList& items, + TQWidget *parent, + bool ask, bool showProgress ) +{ + if ( items.isEmpty() ) { + KMessageBox::information( parent, + i18n("You did not select a file to delete."), + i18n("Nothing to Delete") ); + return 0L; + } + + KURL::List urls; + TQStringList files; + KFileItemListIterator it( items ); + + for ( ; it.current(); ++it ) { + KURL url = (*it)->url(); + urls.append( url ); + if ( url.isLocalFile() ) + files.append( url.path() ); + else + files.append( url.prettyURL() ); + } + + bool doIt = !ask; + if ( ask ) { + int ret; + if ( items.count() == 1 ) { + ret = KMessageBox::warningContinueCancel( parent, + i18n( "Do you really want to delete\n '%1'?" ) + .arg( files.first() ), + i18n("Delete File"), + KStdGuiItem::del(), "AskForDelete" ); + } + else + ret = KMessageBox::warningContinueCancelList( parent, + i18n("Do you really want to delete this item?", "Do you really want to delete these %n items?", items.count() ), + files, + i18n("Delete Files"), + KStdGuiItem::del(), "AskForDelete" ); + doIt = (ret == KMessageBox::Continue); + } + + if ( doIt ) { + TDEIO::DeleteJob *job = TDEIO::del( urls, false, showProgress ); + job->setWindow (topLevelWidget()); + job->setAutoErrorHandlingEnabled( true, parent ); + return job; + } + + return 0L; +} + +void KDirOperator::deleteSelected() +{ + if ( !m_fileView ) + return; + + const KFileItemList *list = m_fileView->selectedItems(); + if ( list ) + del( *list ); +} + +TDEIO::CopyJob * KDirOperator::trash( const KFileItemList& items, + TQWidget *parent, + bool ask, bool showProgress ) +{ + if ( items.isEmpty() ) { + KMessageBox::information( parent, + i18n("You did not select a file to trash."), + i18n("Nothing to Trash") ); + return 0L; + } + + KURL::List urls; + TQStringList files; + KFileItemListIterator it( items ); + + for ( ; it.current(); ++it ) { + KURL url = (*it)->url(); + urls.append( url ); + if ( url.isLocalFile() ) + files.append( url.path() ); + else + files.append( url.prettyURL() ); + } + + bool doIt = !ask; + if ( ask ) { + int ret; + if ( items.count() == 1 ) { + ret = KMessageBox::warningContinueCancel( parent, + i18n( "Do you really want to trash\n '%1'?" ) + .arg( files.first() ), + i18n("Trash File"), + KGuiItem(i18n("to trash", "&Trash"),"edittrash"), "AskForTrash" ); + } + else + ret = KMessageBox::warningContinueCancelList( parent, + i18n("translators: not called for n == 1", "Do you really want to trash these %n items?", items.count() ), + files, + i18n("Trash Files"), + KGuiItem(i18n("to trash", "&Trash"),"edittrash"), "AskForTrash" ); + doIt = (ret == KMessageBox::Continue); + } + + if ( doIt ) { + TDEIO::CopyJob *job = TDEIO::trash( urls, showProgress ); + job->setWindow (topLevelWidget()); + job->setAutoErrorHandlingEnabled( true, parent ); + return job; + } + + return 0L; +} + +void KDirOperator::trashSelected(TDEAction::ActivationReason reason, TQt::ButtonState state) +{ + if ( !m_fileView ) + return; + + if ( reason == TDEAction::PopupMenuActivation && ( state & ShiftButton ) ) { + deleteSelected(); + return; + } + + const KFileItemList *list = m_fileView->selectedItems(); + if ( list ) + trash( *list, this ); +} + +void KDirOperator::close() +{ + resetCursor(); + pendingMimeTypes.clear(); + myCompletion.clear(); + myDirCompletion.clear(); + myCompleteListDirty = true; + dir->stop(); +} + +void KDirOperator::checkPath(const TQString &, bool /*takeFiles*/) // SLOT +{ +#if 0 + // copy the argument in a temporary string + TQString text = _txt; + // it's unlikely to happen, that at the beginning are spaces, but + // for the end, it happens quite often, I guess. + text = text.stripWhiteSpace(); + // if the argument is no URL (the check is quite fragil) and it's + // no absolute path, we add the current directory to get a correct url + if (text.find(':') < 0 && text[0] != '/') + text.insert(0, currUrl); + + // in case we have a selection defined and someone patched the file- + // name, we check, if the end of the new name is changed. + if (!selection.isNull()) { + int position = text.findRev('/'); + ASSERT(position >= 0); // we already inserted the current dir in case + TQString filename = text.mid(position + 1, text.length()); + if (filename != selection) + selection = TQString::null; + } + + KURL u(text); // I have to take care of entered URLs + bool filenameEntered = false; + + if (u.isLocalFile()) { + // the empty path is kind of a hack + KFileItem i("", u.path()); + if (i.isDir()) + setURL(text, true); + else { + if (takeFiles) + if (acceptOnlyExisting && !i.isFile()) + warning("you entered an invalid URL"); + else + filenameEntered = true; + } + } else + setURL(text, true); + + if (filenameEntered) { + filename_ = u.url(); + emit fileSelected(filename_); + + TQApplication::restoreOverrideCursor(); + + accept(); + } +#endif + kdDebug(tdefile_area) << "TODO KDirOperator::checkPath()" << endl; +} + +void KDirOperator::setURL(const KURL& _newurl, bool clearforward) +{ + KURL newurl; + + if ( !_newurl.isValid() ) + newurl.setPath( TQDir::homeDirPath() ); + else + newurl = _newurl; + + TQString pathstr = newurl.path(+1); + newurl.setPath(pathstr); + + // already set + if ( newurl.equals( currUrl, true ) ) + return; + + if ( !isReadable( newurl ) ) { + // maybe newurl is a file? check its parent directory + newurl.cd(TQString::fromLatin1("..")); + if ( !isReadable( newurl ) ) { + resetCursor(); + KMessageBox::error(viewWidget(), + i18n("The specified folder does not exist " + "or was not readable.")); + return; + } + } + + if (clearforward) { + // autodelete should remove this one + backStack.push(new KURL(currUrl)); + forwardStack.clear(); + } + + d->lastURL = currUrl.url(-1); + currUrl = newurl; + + pathChanged(); + emit urlEntered(newurl); + + // enable/disable actions + forwardAction->setEnabled( !forwardStack.isEmpty() ); + backAction->setEnabled( !backStack.isEmpty() ); + upAction->setEnabled( !isRoot() ); + + openURL( newurl ); +} + +void KDirOperator::updateDir() +{ + dir->emitChanges(); + if ( m_fileView ) + m_fileView->listingCompleted(); +} + +void KDirOperator::rereadDir() +{ + pathChanged(); + openURL( currUrl, false, true ); +} + + +bool KDirOperator::openURL( const KURL& url, bool keep, bool reload ) +{ + bool result = dir->openURL( url, keep, reload ); + if ( !result ) // in that case, neither completed() nor canceled() will be emitted by KDL + slotCanceled(); + + return result; +} + +// Protected +void KDirOperator::pathChanged() +{ + if (!m_fileView) + return; + + pendingMimeTypes.clear(); + m_fileView->clear(); + myCompletion.clear(); + myDirCompletion.clear(); + + // it may be, that we weren't ready at this time + TQApplication::restoreOverrideCursor(); + + // when TDEIO::Job emits finished, the slot will restore the cursor + TQApplication::setOverrideCursor( tqwaitCursor ); + + if ( !isReadable( currUrl )) { + KMessageBox::error(viewWidget(), + i18n("The specified folder does not exist " + "or was not readable.")); + if (backStack.isEmpty()) + home(); + else + back(); + } +} + +void KDirOperator::slotRedirected( const KURL& newURL ) +{ + currUrl = newURL; + pendingMimeTypes.clear(); + myCompletion.clear(); + myDirCompletion.clear(); + myCompleteListDirty = true; + emit urlEntered( newURL ); +} + +// Code pinched from kfm then hacked +void KDirOperator::back() +{ + if ( backStack.isEmpty() ) + return; + + forwardStack.push( new KURL(currUrl) ); + + KURL *s = backStack.pop(); + + setURL(*s, false); + delete s; +} + +// Code pinched from kfm then hacked +void KDirOperator::forward() +{ + if ( forwardStack.isEmpty() ) + return; + + backStack.push(new KURL(currUrl)); + + KURL *s = forwardStack.pop(); + setURL(*s, false); + delete s; +} + +KURL KDirOperator::url() const +{ + return currUrl; +} + +void KDirOperator::cdUp() +{ + KURL tmp(currUrl); + tmp.cd(TQString::fromLatin1("..")); + setURL(tmp, true); +} + +void KDirOperator::home() +{ + KURL u; + u.setPath( TQDir::homeDirPath() ); + setURL(u, true); +} + +void KDirOperator::clearFilter() +{ + dir->setNameFilter( TQString::null ); + dir->clearMimeFilter(); + checkPreviewSupport(); +} + +void KDirOperator::setNameFilter(const TQString& filter) +{ + dir->setNameFilter(filter); + checkPreviewSupport(); +} + +void KDirOperator::setMimeFilter( const TQStringList& mimetypes ) +{ + dir->setMimeFilter( mimetypes ); + checkPreviewSupport(); +} + +bool KDirOperator::checkPreviewSupport() +{ + TDEToggleAction *previewAction = static_cast( myActionCollection->action( "preview" )); + + bool hasPreviewSupport = false; + TDEConfig *kc = TDEGlobal::config(); + TDEConfigGroupSaver cs( kc, ConfigGroup ); + if ( kc->readBoolEntry( "Show Default Preview", true ) ) + hasPreviewSupport = checkPreviewInternal(); + + previewAction->setEnabled( hasPreviewSupport ); + return hasPreviewSupport; +} + +bool KDirOperator::checkPreviewInternal() const +{ + TQStringList supported = TDEIO::PreviewJob::supportedMimeTypes(); + // no preview support for directories? + if ( dirOnlyMode() && supported.findIndex( "inode/directory" ) == -1 ) + return false; + + TQStringList mimeTypes = dir->mimeFilters(); + TQStringList nameFilter = TQStringList::split( " ", dir->nameFilter() ); + + if ( mimeTypes.isEmpty() && nameFilter.isEmpty() && !supported.isEmpty() ) + return true; + else { + TQRegExp r; + r.setWildcard( true ); // the "mimetype" can be "image/*" + + if ( !mimeTypes.isEmpty() ) { + TQStringList::Iterator it = supported.begin(); + + for ( ; it != supported.end(); ++it ) { + r.setPattern( *it ); + + TQStringList result = mimeTypes.grep( r ); + if ( !result.isEmpty() ) { // matches! -> we want previews + return true; + } + } + } + + if ( !nameFilter.isEmpty() ) { + // find the mimetypes of all the filter-patterns and + KServiceTypeFactory *fac = KServiceTypeFactory::self(); + TQStringList::Iterator it1 = nameFilter.begin(); + for ( ; it1 != nameFilter.end(); ++it1 ) { + if ( (*it1) == "*" ) { + return true; + } + + KMimeType *mt = fac->findFromPattern( *it1 ); + if ( !mt ) + continue; + TQString mime = mt->name(); + delete mt; + + // the "mimetypes" we get from the PreviewJob can be "image/*" + // so we need to check in wildcard mode + TQStringList::Iterator it2 = supported.begin(); + for ( ; it2 != supported.end(); ++it2 ) { + r.setPattern( *it2 ); + if ( r.search( mime ) != -1 ) { + return true; + } + } + } + } + } + + return false; +} + +KFileView* KDirOperator::createView( TQWidget* parent, KFile::FileView view ) +{ + KFileView* new_view = 0L; + bool separateDirs = KFile::isSeparateDirs( view ); + bool preview = ( KFile::isPreviewInfo(view) || KFile::isPreviewContents( view ) ); + + if ( separateDirs || preview ) { + KCombiView *combi = 0L; + if (separateDirs) + { + combi = new KCombiView( parent, "combi view" ); + combi->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles); + } + + KFileView* v = 0L; + if ( KFile::isSimpleView( view ) ) + v = createView( combi, KFile::Simple ); + else + v = createView( combi, KFile::Detail ); + + v->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles); + + if (combi) + combi->setRight( v ); + + if (preview) + { + KFilePreview* pView = new KFilePreview( combi ? combi : v, parent, "preview" ); + pView->setOnlyDoubleClickSelectsFiles(d->onlyDoubleClickSelectsFiles); + new_view = pView; + } + else + new_view = combi; + } + else if ( KFile::isDetailView( view ) && !preview ) { + new_view = new KFileDetailView( parent, "detail view"); + new_view->setViewName( i18n("Detailed View") ); + } + else /* if ( KFile::isSimpleView( view ) && !preview ) */ { + KFileIconView *iconView = new KFileIconView( parent, "simple view"); + new_view = iconView; + new_view->setViewName( i18n("Short View") ); + } + + new_view->widget()->setAcceptDrops(acceptDrops()); + return new_view; +} + +void KDirOperator::setAcceptDrops(bool b) +{ + if (m_fileView) + m_fileView->widget()->setAcceptDrops(b); + TQWidget::setAcceptDrops(b); +} + +void KDirOperator::setDropOptions(int options) +{ + d->dropOptions = options; + if (m_fileView) + m_fileView->setDropOptions(options); +} + +void KDirOperator::setView( KFile::FileView view ) +{ + bool separateDirs = KFile::isSeparateDirs( view ); + bool preview=( KFile::isPreviewInfo(view) || KFile::isPreviewContents( view ) ); + + if (view == KFile::Default) { + if ( KFile::isDetailView( (KFile::FileView) defaultView ) ) + view = KFile::Detail; + else + view = KFile::Simple; + + separateDirs = KFile::isSeparateDirs( static_cast(defaultView) ); + preview = ( KFile::isPreviewInfo( static_cast(defaultView) ) || + KFile::isPreviewContents( static_cast(defaultView) ) ) + && myActionCollection->action("preview")->isEnabled(); + + if ( preview ) { // instantiates KFileMetaPreview and calls setView() + m_viewKind = defaultView; + slotDefaultPreview(); + return; + } + else if ( !separateDirs ) + separateDirsAction->setChecked(true); + } + + // if we don't have any files, we can't separate dirs from files :) + if ( (mode() & KFile::File) == 0 && + (mode() & KFile::Files) == 0 ) { + separateDirs = false; + separateDirsAction->setEnabled( false ); + } + + m_viewKind = static_cast(view) | (separateDirs ? KFile::SeparateDirs : 0); + view = static_cast(m_viewKind); + + KFileView *new_view = createView( this, view ); + if ( preview ) { + // we keep the preview-_widget_ around, but not the KFilePreview. + // KFilePreview::setPreviewWidget handles the reparenting for us + static_cast(new_view)->setPreviewWidget(myPreview, url()); + } + + setView( new_view ); +} + + +void KDirOperator::connectView(KFileView *view) +{ + // TODO: do a real timer and restart it after that + pendingMimeTypes.clear(); + bool listDir = true; + + if ( dirOnlyMode() ) + view->setViewMode(KFileView::Directories); + else + view->setViewMode(KFileView::All); + + if ( myMode & KFile::Files ) + view->setSelectionMode( KFile::Extended ); + else + view->setSelectionMode( KFile::Single ); + + if (m_fileView) + { + if ( d->config ) // save and restore the views' configuration + { + m_fileView->writeConfig( d->config, d->configGroup ); + view->readConfig( d->config, d->configGroup ); + } + + // transfer the state from old view to new view + view->clear(); + view->addItemList( *m_fileView->items() ); + listDir = false; + + if ( m_fileView->widget()->hasFocus() ) + view->widget()->setFocus(); + + KFileItem *oldCurrentItem = m_fileView->currentFileItem(); + if ( oldCurrentItem ) { + view->setCurrentItem( oldCurrentItem ); + view->setSelected( oldCurrentItem, false ); + view->ensureItemVisible( oldCurrentItem ); + } + + const KFileItemList *oldSelected = m_fileView->selectedItems(); + if ( !oldSelected->isEmpty() ) { + KFileItemListIterator it( *oldSelected ); + for ( ; it.current(); ++it ) + view->setSelected( it.current(), true ); + } + + m_fileView->widget()->hide(); + delete m_fileView; + } + + else + { + if ( d->config ) + view->readConfig( d->config, d->configGroup ); + } + + m_fileView = view; + m_fileView->setDropOptions(d->dropOptions); + viewActionCollection = 0L; + KFileViewSignaler *sig = view->signaler(); + + connect(sig, TQT_SIGNAL( activatedMenu(const KFileItem *, const TQPoint& ) ), + this, TQT_SLOT( activatedMenu(const KFileItem *, const TQPoint& ))); + connect(sig, TQT_SIGNAL( dirActivated(const KFileItem *) ), + this, TQT_SLOT( selectDir(const KFileItem*) ) ); + connect(sig, TQT_SIGNAL( fileSelected(const KFileItem *) ), + this, TQT_SLOT( selectFile(const KFileItem*) ) ); + connect(sig, TQT_SIGNAL( fileHighlighted(const KFileItem *) ), + this, TQT_SLOT( highlightFile(const KFileItem*) )); + connect(sig, TQT_SIGNAL( sortingChanged( TQDir::SortSpec ) ), + this, TQT_SLOT( slotViewSortingChanged( TQDir::SortSpec ))); + connect(sig, TQT_SIGNAL( dropped(const KFileItem *, TQDropEvent*, const KURL::List&) ), + this, TQT_SIGNAL( dropped(const KFileItem *, TQDropEvent*, const KURL::List&)) ); + + if ( reverseAction->isChecked() != m_fileView->isReversed() ) + slotSortReversed(); + + updateViewActions(); + m_fileView->widget()->resize(size()); + m_fileView->widget()->show(); + + if ( listDir ) { + TQApplication::setOverrideCursor( tqwaitCursor ); + openURL( currUrl ); + } + else + view->listingCompleted(); +} + +KFile::Mode KDirOperator::mode() const +{ + return myMode; +} + +void KDirOperator::setMode(KFile::Mode m) +{ + if (myMode == m) + return; + + myMode = m; + + dir->setDirOnlyMode( dirOnlyMode() ); + + // reset the view with the different mode + setView( static_cast(m_viewKind) ); +} + +void KDirOperator::setView(KFileView *view) +{ + if ( view == m_fileView ) { + return; + } + + setFocusProxy(view->widget()); + view->setSorting( mySorting ); + view->setOnlyDoubleClickSelectsFiles( d->onlyDoubleClickSelectsFiles ); + connectView(view); // also deletes the old view + + emit viewChanged( view ); +} + +void KDirOperator::setDirLister( KDirLister *lister ) +{ + if ( lister == dir ) // sanity check + return; + + delete dir; + dir = lister; + + dir->setAutoUpdate( true ); + + TQWidget* mainWidget = topLevelWidget(); + dir->setMainWindow (mainWidget); + kdDebug (tdefile_area) << "mainWidget=" << mainWidget << endl; + + connect( dir, TQT_SIGNAL( percent( int )), + TQT_SLOT( slotProgress( int ) )); + connect( dir, TQT_SIGNAL(started( const KURL& )), TQT_SLOT(slotStarted())); + connect( dir, TQT_SIGNAL(newItems(const KFileItemList &)), + TQT_SLOT(insertNewFiles(const KFileItemList &))); + connect( dir, TQT_SIGNAL(completed()), TQT_SLOT(slotIOFinished())); + connect( dir, TQT_SIGNAL(canceled()), TQT_SLOT(slotCanceled())); + connect( dir, TQT_SIGNAL(deleteItem(KFileItem *)), + TQT_SLOT(itemDeleted(KFileItem *))); + connect( dir, TQT_SIGNAL(redirection( const KURL& )), + TQT_SLOT( slotRedirected( const KURL& ))); + connect( dir, TQT_SIGNAL( clear() ), TQT_SLOT( slotClearView() )); + connect( dir, TQT_SIGNAL( refreshItems( const KFileItemList& ) ), + TQT_SLOT( slotRefreshItems( const KFileItemList& ) ) ); +} + +void KDirOperator::insertNewFiles(const KFileItemList &newone) +{ + if ( newone.isEmpty() || !m_fileView ) + return; + + myCompleteListDirty = true; + m_fileView->addItemList( newone ); + emit updateInformation(m_fileView->numDirs(), m_fileView->numFiles()); + + KFileItem *item; + KFileItemListIterator it( newone ); + + while ( (item = it.current()) ) { + // highlight the dir we come from, if possible + if ( d->dirHighlighting && item->isDir() && + item->url().url(-1) == d->lastURL ) { + m_fileView->setCurrentItem( item ); + m_fileView->ensureItemVisible( item ); + } + + ++it; + } + + TQTimer::singleShot(200, this, TQT_SLOT(resetCursor())); +} + +void KDirOperator::selectDir(const KFileItem *item) +{ + setURL(item->url(), true); +} + +void KDirOperator::itemDeleted(KFileItem *item) +{ + pendingMimeTypes.removeRef( item ); + if ( m_fileView ) + { + m_fileView->removeItem( static_cast( item )); + emit updateInformation(m_fileView->numDirs(), m_fileView->numFiles()); + } +} + +void KDirOperator::selectFile(const KFileItem *item) +{ + TQApplication::restoreOverrideCursor(); + + emit fileSelected( item ); +} + +void KDirOperator::setCurrentItem( const TQString& filename ) +{ + if ( m_fileView ) { + const KFileItem *item = 0L; + + if ( !filename.isNull() ) + item = static_cast(dir->findByName( filename )); + + m_fileView->clearSelection(); + if ( item ) { + m_fileView->setCurrentItem( item ); + m_fileView->setSelected( item, true ); + m_fileView->ensureItemVisible( item ); + } + } +} + +TQString KDirOperator::makeCompletion(const TQString& string) +{ + if ( string.isEmpty() ) { + m_fileView->clearSelection(); + return TQString::null; + } + + prepareCompletionObjects(); + return myCompletion.makeCompletion( string ); +} + +TQString KDirOperator::makeDirCompletion(const TQString& string) +{ + if ( string.isEmpty() ) { + m_fileView->clearSelection(); + return TQString::null; + } + + prepareCompletionObjects(); + return myDirCompletion.makeCompletion( string ); +} + +void KDirOperator::prepareCompletionObjects() +{ + if ( !m_fileView ) + return; + + if ( myCompleteListDirty ) { // create the list of all possible completions + KFileItemListIterator it( *(m_fileView->items()) ); + for( ; it.current(); ++it ) { + KFileItem *item = it.current(); + + myCompletion.addItem( item->name() ); + if ( item->isDir() ) + myDirCompletion.addItem( item->name() ); + } + myCompleteListDirty = false; + } +} + +void KDirOperator::slotCompletionMatch(const TQString& match) +{ + setCurrentItem( match ); + emit completion( match ); +} + +void KDirOperator::setupActions() +{ + myActionCollection = new TDEActionCollection( topLevelWidget(), TQT_TQOBJECT(this), "KDirOperator::myActionCollection" ); + + actionMenu = new TDEActionMenu( i18n("Menu"), myActionCollection, "popupMenu" ); + upAction = KStdAction::up( TQT_TQOBJECT(this), TQT_SLOT( cdUp() ), myActionCollection, "up" ); + upAction->setText( i18n("Parent Folder") ); + backAction = KStdAction::back( TQT_TQOBJECT(this), TQT_SLOT( back() ), myActionCollection, "back" ); + forwardAction = KStdAction::forward( TQT_TQOBJECT(this), TQT_SLOT(forward()), myActionCollection, "forward" ); + homeAction = KStdAction::home( TQT_TQOBJECT(this), TQT_SLOT( home() ), myActionCollection, "home" ); + homeAction->setText(i18n("Home Folder")); + reloadAction = KStdAction::redisplay( TQT_TQOBJECT(this), TQT_SLOT(rereadDir()), myActionCollection, "reload" ); + actionSeparator = new TDEActionSeparator( myActionCollection, "separator" ); + d->viewActionSeparator = new TDEActionSeparator( myActionCollection, + "viewActionSeparator" ); + mkdirAction = new TDEAction( i18n("New Folder..."), 0, + TQT_TQOBJECT(this), TQT_SLOT( mkdir() ), myActionCollection, "mkdir" ); + TDEAction* trash = new TDEAction( i18n( "Move to Trash" ), "edittrash", Key_Delete, myActionCollection, "trash" ); + connect( trash, TQT_SIGNAL( activated( TDEAction::ActivationReason, TQt::ButtonState ) ), + this, TQT_SLOT( trashSelected( TDEAction::ActivationReason, TQt::ButtonState ) ) ); + new TDEAction( i18n( "Delete" ), "editdelete", SHIFT+Key_Delete, TQT_TQOBJECT(this), + TQT_SLOT( deleteSelected() ), myActionCollection, "delete" ); + mkdirAction->setIcon( TQString::fromLatin1("folder_new") ); + reloadAction->setText( i18n("Reload") ); + reloadAction->setShortcut( TDEStdAccel::shortcut( TDEStdAccel::Reload )); + + + // the sort menu actions + sortActionMenu = new TDEActionMenu( i18n("Sorting"), myActionCollection, "sorting menu"); + byNameAction = new TDERadioAction( i18n("By Name"), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotSortByName() ), + myActionCollection, "by name" ); + byDateAction = new TDERadioAction( i18n("By Date"), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotSortByDate() ), + myActionCollection, "by date" ); + bySizeAction = new TDERadioAction( i18n("By Size"), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotSortBySize() ), + myActionCollection, "by size" ); + reverseAction = new TDEToggleAction( i18n("Reverse"), 0, + TQT_TQOBJECT(this), TQT_SLOT( slotSortReversed() ), + myActionCollection, "reversed" ); + + TQString sortGroup = TQString::fromLatin1("sort"); + byNameAction->setExclusiveGroup( sortGroup ); + byDateAction->setExclusiveGroup( sortGroup ); + bySizeAction->setExclusiveGroup( sortGroup ); + + + dirsFirstAction = new TDEToggleAction( i18n("Folders First"), 0, + myActionCollection, "dirs first"); + caseInsensitiveAction = new TDEToggleAction(i18n("Case Insensitive"), 0, + myActionCollection, "case insensitive" ); + + connect( dirsFirstAction, TQT_SIGNAL( toggled( bool ) ), + TQT_SLOT( slotToggleDirsFirst() )); + connect( caseInsensitiveAction, TQT_SIGNAL( toggled( bool ) ), + TQT_SLOT( slotToggleIgnoreCase() )); + + + + // the view menu actions + viewActionMenu = new TDEActionMenu( i18n("&View"), myActionCollection, "view menu" ); + connect( viewActionMenu->popupMenu(), TQT_SIGNAL( aboutToShow() ), + TQT_SLOT( insertViewDependentActions() )); + + shortAction = new TDERadioAction( i18n("Short View"), "view_multicolumn", + TDEShortcut(), myActionCollection, "short view" ); + detailedAction = new TDERadioAction( i18n("Detailed View"), "view_detailed", + TDEShortcut(), myActionCollection, "detailed view" ); + + showHiddenAction = new TDEToggleAction( i18n("Show Hidden Files"), TDEShortcut(), + myActionCollection, "show hidden" ); +// showHiddenAction->setCheckedState( i18n("Hide Hidden Files") ); + separateDirsAction = new TDEToggleAction( i18n("Separate Folders"), TDEShortcut(), + TQT_TQOBJECT(this), + TQT_SLOT(slotSeparateDirs()), + myActionCollection, "separate dirs" ); + TDEToggleAction *previewAction = new TDEToggleAction(i18n("Show Preview"), + "thumbnail", TDEShortcut(), + myActionCollection, + "preview" ); + previewAction->setCheckedState(i18n("Hide Preview")); + connect( previewAction, TQT_SIGNAL( toggled( bool )), + TQT_SLOT( togglePreview( bool ))); + + + TQString viewGroup = TQString::fromLatin1("view"); + shortAction->setExclusiveGroup( viewGroup ); + detailedAction->setExclusiveGroup( viewGroup ); + + connect( shortAction, TQT_SIGNAL( activated() ), + TQT_SLOT( slotSimpleView() )); + connect( detailedAction, TQT_SIGNAL( activated() ), + TQT_SLOT( slotDetailedView() )); + connect( showHiddenAction, TQT_SIGNAL( toggled( bool ) ), + TQT_SLOT( slotToggleHidden( bool ) )); + + new TDEAction( i18n("Properties"), TDEShortcut(ALT+Key_Return), TQT_TQOBJECT(this), + TQT_SLOT(slotProperties()), myActionCollection, "properties" ); +} + +void KDirOperator::setupMenu() +{ + setupMenu(AllActions); +} + +void KDirOperator::setupMenu(int whichActions) +{ + // first fill the submenus (sort and view) + sortActionMenu->popupMenu()->clear(); + sortActionMenu->insert( byNameAction ); + sortActionMenu->insert( byDateAction ); + sortActionMenu->insert( bySizeAction ); + sortActionMenu->insert( actionSeparator ); + sortActionMenu->insert( reverseAction ); + sortActionMenu->insert( dirsFirstAction ); + sortActionMenu->insert( caseInsensitiveAction ); + + // now plug everything into the popupmenu + actionMenu->popupMenu()->clear(); + if (whichActions & NavActions) + { + actionMenu->insert( upAction ); + actionMenu->insert( backAction ); + actionMenu->insert( forwardAction ); + actionMenu->insert( homeAction ); + actionMenu->insert( actionSeparator ); + } + + if (whichActions & FileActions) + { + actionMenu->insert( mkdirAction ); + if (currUrl.isLocalFile() && !(TDEApplication::keyboardMouseState() & TQt::ShiftButton)) + actionMenu->insert( myActionCollection->action( "trash" ) ); + TDEConfig *globalconfig = TDEGlobal::config(); + TDEConfigGroupSaver cs( globalconfig, TQString::fromLatin1("KDE") ); + if (!currUrl.isLocalFile() || (TDEApplication::keyboardMouseState() & TQt::ShiftButton) || + globalconfig->readBoolEntry("ShowDeleteCommand", false)) + actionMenu->insert( myActionCollection->action( "delete" ) ); + actionMenu->insert( actionSeparator ); + } + + if (whichActions & SortActions) + { + actionMenu->insert( sortActionMenu ); + actionMenu->insert( actionSeparator ); + } + + if (whichActions & ViewActions) + { + actionMenu->insert( viewActionMenu ); + actionMenu->insert( actionSeparator ); + } + + if (whichActions & FileActions) + { + actionMenu->insert( myActionCollection->action( "properties" ) ); + } +} + +void KDirOperator::updateSortActions() +{ + if ( KFile::isSortByName( mySorting ) ) + byNameAction->setChecked( true ); + else if ( KFile::isSortByDate( mySorting ) ) + byDateAction->setChecked( true ); + else if ( KFile::isSortBySize( mySorting ) ) + bySizeAction->setChecked( true ); + + dirsFirstAction->setChecked( KFile::isSortDirsFirst( mySorting ) ); + caseInsensitiveAction->setChecked( KFile::isSortCaseInsensitive(mySorting) ); + caseInsensitiveAction->setEnabled( KFile::isSortByName( mySorting ) ); + + if ( m_fileView ) + reverseAction->setChecked( m_fileView->isReversed() ); +} + +void KDirOperator::updateViewActions() +{ + KFile::FileView fv = static_cast( m_viewKind ); + + separateDirsAction->setChecked( KFile::isSeparateDirs( fv ) && + separateDirsAction->isEnabled() ); + + shortAction->setChecked( KFile::isSimpleView( fv )); + detailedAction->setChecked( KFile::isDetailView( fv )); +} + +void KDirOperator::readConfig( TDEConfig *kc, const TQString& group ) +{ + if ( !kc ) + return; + TQString oldGroup = kc->group(); + if ( !group.isEmpty() ) + kc->setGroup( group ); + + defaultView = 0; + int sorting = 0; + + TQString viewStyle = kc->readEntry( TQString::fromLatin1("View Style"), + TQString::fromLatin1("Simple") ); + if ( viewStyle == TQString::fromLatin1("Detail") ) + defaultView |= KFile::Detail; + else + defaultView |= KFile::Simple; + if ( kc->readBoolEntry( TQString::fromLatin1("Separate Directories"), + DefaultMixDirsAndFiles ) ) + defaultView |= KFile::SeparateDirs; + if ( kc->readBoolEntry(TQString::fromLatin1("Show Preview"), false)) + defaultView |= KFile::PreviewContents; + + if ( kc->readBoolEntry( TQString::fromLatin1("Sort case insensitively"), + DefaultCaseInsensitive ) ) + sorting |= TQDir::IgnoreCase; + if ( kc->readBoolEntry( TQString::fromLatin1("Sort directories first"), + DefaultDirsFirst ) ) + sorting |= TQDir::DirsFirst; + + + TQString name = TQString::fromLatin1("Name"); + TQString sortBy = kc->readEntry( TQString::fromLatin1("Sort by"), name ); + if ( sortBy == name ) + sorting |= TQDir::Name; + else if ( sortBy == TQString::fromLatin1("Size") ) + sorting |= TQDir::Size; + else if ( sortBy == TQString::fromLatin1("Date") ) + sorting |= TQDir::Time; + + mySorting = static_cast( sorting ); + setSorting( mySorting ); + + + if ( kc->readBoolEntry( TQString::fromLatin1("Show hidden files"), + DefaultShowHidden ) ) { + showHiddenAction->setChecked( true ); + dir->setShowingDotFiles( true ); + } + if ( kc->readBoolEntry( TQString::fromLatin1("Sort reversed"), + DefaultSortReversed ) ) + reverseAction->setChecked( true ); + + kc->setGroup( oldGroup ); +} + +void KDirOperator::writeConfig( TDEConfig *kc, const TQString& group ) +{ + if ( !kc ) + return; + + const TQString oldGroup = kc->group(); + + if ( !group.isEmpty() ) + kc->setGroup( group ); + + TQString sortBy = TQString::fromLatin1("Name"); + if ( KFile::isSortBySize( mySorting ) ) + sortBy = TQString::fromLatin1("Size"); + else if ( KFile::isSortByDate( mySorting ) ) + sortBy = TQString::fromLatin1("Date"); + kc->writeEntry( TQString::fromLatin1("Sort by"), sortBy ); + + kc->writeEntry( TQString::fromLatin1("Sort reversed"), + reverseAction->isChecked() ); + kc->writeEntry( TQString::fromLatin1("Sort case insensitively"), + caseInsensitiveAction->isChecked() ); + kc->writeEntry( TQString::fromLatin1("Sort directories first"), + dirsFirstAction->isChecked() ); + + // don't save the separate dirs or preview when an application specific + // preview is in use. + bool appSpecificPreview = false; + if ( myPreview ) { + TQWidget *preview = const_cast( myPreview ); // grmbl + KFileMetaPreview *tmp = dynamic_cast( preview ); + appSpecificPreview = (tmp == 0L); + } + + if ( !appSpecificPreview ) { + if ( separateDirsAction->isEnabled() ) + kc->writeEntry( TQString::fromLatin1("Separate Directories"), + separateDirsAction->isChecked() ); + + TDEToggleAction *previewAction = static_cast(myActionCollection->action("preview")); + if ( previewAction->isEnabled() ) { + bool hasPreview = previewAction->isChecked(); + kc->writeEntry( TQString::fromLatin1("Show Preview"), hasPreview ); + } + } + + kc->writeEntry( TQString::fromLatin1("Show hidden files"), + showHiddenAction->isChecked() ); + + KFile::FileView fv = static_cast( m_viewKind ); + TQString style; + if ( KFile::isDetailView( fv ) ) + style = TQString::fromLatin1("Detail"); + else if ( KFile::isSimpleView( fv ) ) + style = TQString::fromLatin1("Simple"); + kc->writeEntry( TQString::fromLatin1("View Style"), style ); + + kc->setGroup( oldGroup ); +} + + +void KDirOperator::resizeEvent( TQResizeEvent * ) +{ + if (m_fileView) + m_fileView->widget()->resize( size() ); + + if ( TQT_BASE_OBJECT(progress->parent()) == TQT_BASE_OBJECT(this) ) // might be reparented into a statusbar + progress->move(2, height() - progress->height() -2); +} + +void KDirOperator::setOnlyDoubleClickSelectsFiles( bool enable ) +{ + d->onlyDoubleClickSelectsFiles = enable; + if ( m_fileView ) + m_fileView->setOnlyDoubleClickSelectsFiles( enable ); +} + +bool KDirOperator::onlyDoubleClickSelectsFiles() const +{ + return d->onlyDoubleClickSelectsFiles; +} + +void KDirOperator::slotStarted() +{ + progress->setProgress( 0 ); + // delay showing the progressbar for one second + d->progressDelayTimer->start( 1000, true ); +} + +void KDirOperator::slotShowProgress() +{ + progress->raise(); + progress->show(); + TQApplication::flushX(); +} + +void KDirOperator::slotProgress( int percent ) +{ + progress->setProgress( percent ); + // we have to redraw this as fast as possible + if ( progress->isVisible() ) + TQApplication::flushX(); +} + + +void KDirOperator::slotIOFinished() +{ + d->progressDelayTimer->stop(); + slotProgress( 100 ); + progress->hide(); + emit finishedLoading(); + resetCursor(); + + if ( m_fileView ) + m_fileView->listingCompleted(); +} + +void KDirOperator::slotCanceled() +{ + emit finishedLoading(); + resetCursor(); + + if ( m_fileView ) + m_fileView->listingCompleted(); +} + +KProgress * KDirOperator::progressBar() const +{ + return progress; +} + +void KDirOperator::clearHistory() +{ + backStack.clear(); + backAction->setEnabled( false ); + forwardStack.clear(); + forwardAction->setEnabled( false ); +} + +void KDirOperator::slotViewActionAdded( TDEAction *action ) +{ + if ( viewActionMenu->popupMenu()->count() == 5 ) // need to add a separator + viewActionMenu->insert( d->viewActionSeparator ); + + viewActionMenu->insert( action ); +} + +void KDirOperator::slotViewActionRemoved( TDEAction *action ) +{ + viewActionMenu->remove( action ); + + if ( viewActionMenu->popupMenu()->count() == 6 ) // remove the separator + viewActionMenu->remove( d->viewActionSeparator ); +} + +void KDirOperator::slotViewSortingChanged( TQDir::SortSpec sort ) +{ + mySorting = sort; + updateSortActions(); +} + +void KDirOperator::setEnableDirHighlighting( bool enable ) +{ + d->dirHighlighting = enable; +} + +bool KDirOperator::dirHighlighting() const +{ + return d->dirHighlighting; +} + +void KDirOperator::slotProperties() +{ + if ( m_fileView ) { + const KFileItemList *list = m_fileView->selectedItems(); + if ( !list->isEmpty() ) + (void) new KPropertiesDialog( *list, this, "props dlg", true); + } +} + +void KDirOperator::slotClearView() +{ + if ( m_fileView ) + m_fileView->clearView(); +} + +// ### temporary code +#include +bool KDirOperator::isReadable( const KURL& url ) +{ + if ( !url.isLocalFile() ) + return true; // what else can we say? + + KDE_struct_stat buf; + TQString ts = url.path(+1); + bool readable = ( KDE_stat( TQFile::encodeName( ts ), &buf) == 0 ); + if (readable) { // further checks + DIR *test; + test = opendir( TQFile::encodeName( ts )); // we do it just to test here + readable = (test != 0); + if (test) + closedir(test); + } + return readable; +} + +void KDirOperator::togglePreview( bool on ) +{ + if ( on ) + slotDefaultPreview(); + else + setView( (KFile::FileView) (m_viewKind & ~(KFile::PreviewContents|KFile::PreviewInfo)) ); +} + +void KDirOperator::slotRefreshItems( const KFileItemList& items ) +{ + if ( !m_fileView ) + return; + + KFileItemListIterator it( items ); + for ( ; it.current(); ++it ) + m_fileView->updateView( it.current() ); +} + +void KDirOperator::setViewConfig( TDEConfig *config, const TQString& group ) +{ + d->config = config; + d->configGroup = group; +} + +TDEConfig * KDirOperator::viewConfig() +{ + return d->config; +} + +TQString KDirOperator::viewConfigGroup() const +{ + return d->configGroup; +} + +void KDirOperator::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "tdediroperator.moc" diff --git a/tdeio/tdefile/tdediroperator.h b/tdeio/tdefile/tdediroperator.h new file mode 100644 index 000000000..95bf5c5ba --- /dev/null +++ b/tdeio/tdefile/tdediroperator.h @@ -0,0 +1,950 @@ +// -*- c++ -*- +/* This file is part of the KDE libraries + Copyright (C) 1999 Stephan Kulow + 2000,2001 Carsten Pfeiffer + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KDIROPERATOR_H_ +#define KDIROPERATOR_H_ + +#include +#include + +#include +#include +#include +#include +#include +#include + +class TQPopupMenu; +class TQTimer; + +class TDEAction; +class KDirLister; +class TDEToggleAction; +class TDEActionSeparator; +class TDEActionMenu; +class TQWidgetStack; +class KProgress; +namespace TDEIO { + class CopyJob; + class DeleteJob; +} + +/** + * This widget works as a network transparent filebrowser. You specify a URL + * to display and this url will be loaded via KDirLister. The user can + * browse through directories, highlight and select files, delete or rename + * files. + * + * It supports different views, e.g. a detailed view (see KFileDetailView), + * a simple icon view (see KFileIconView), a combination of two views, + * separating directories and files ( KCombiView). + * + * Additionally, a preview view is available (see KFilePreview), which can + * show either a simple or detailed view and additionally a preview widget + * (see setPreviewWidget()). KImageFilePreview is one implementation + * of a preview widget, that displays previews for all supported filetypes + * utilizing TDEIO::PreviewJob. + * + * Currently, those classes don't support Drag&Drop out of the box -- there + * you have to use your own view-classes. You can use some DnD-aware views + * from Bj�n Sahlstr� until they will be integrated + * into this library. See http://devel-home.kde.org/~pfeiffer/DnD-classes.tar.gz + * + * This widget is the one used in the KFileDialog. + * + * Basic usage is like this: + * \code + * KDirOperator *op = new KDirOperator( KURL( "file:/home/gis" ), this ); + * // some signals you might be interested in + * connect(op, TQT_SIGNAL(urlEntered(const KURL&)), + * TQT_SLOT(urlEntered(const KURL&))); + * connect(op, TQT_SIGNAL(fileHighlighted(const KFileItem *)), + * TQT_SLOT(fileHighlighted(const KFileItem *))); + * connect(op, TQT_SIGNAL(fileSelected(const KFileItem *)), + * TQT_SLOT(fileSelected(const KFileItem *))); + * connect(op, TQT_SIGNAL(finishedLoading()), + * TQT_SLOT(slotLoadingFinished())); + * + * op->readConfig( TDEGlobal::config(), "Your KDiroperator ConfigGroup" ); + * op->setView(KFile::Default); + * \endcode + * + * This will create a childwidget of 'this' showing the directory contents + * of /home/gis in the default-view. The view is determined by the readConfig() + * call, which will read the KDirOperator settings, the user left your program + * with (and which you saved with op->writeConfig()). + * + * @short A widget for displaying files and browsing directories. + * @author Stephan Kulow , Carsten Pfeiffer + */ +class TDEIO_EXPORT KDirOperator : public TQWidget +{ + Q_OBJECT + + public: + /** + * The various action types. These values can be or'd together + * @since 3.1 + */ + enum ActionTypes { SortActions = 1, + ViewActions = 2, + NavActions = 4, + FileActions = 8, + AllActions = 15 }; + /** + * Constructs the KDirOperator with no initial view. As the views are + * configurable, call readConfig() to load the user's configuration + * and then setView to explicitly set a view. + * + * This constructor doesn't start loading the url, setView will do it. + */ + KDirOperator(const KURL& urlName = KURL(), + TQWidget *parent = 0, const char* name = 0); + /** + * Destroys the KDirOperator. + */ + virtual ~KDirOperator(); + + /** + * Enables/disables showing hidden files. + */ + // ### KDE4: make virtual + void setShowHiddenFiles ( bool s ) { showHiddenAction->setChecked( s ); } + + /** + * @returns true when hidden files are shown or false otherwise. + */ + bool showHiddenFiles () const { return showHiddenAction->isChecked(); } + + /** + * Stops loading immediately. You don't need to call this, usually. + */ + void close(); + /// Reimplemented to avoid "hidden virtual" warnings + virtual bool close( bool alsoDelete ) { return TQWidget::close( alsoDelete ); } + + /** + * Sets a filter like "*.cpp *.h *.o". Only files matching that filter + * will be shown. Call updateDir() to apply it. + * + * @see KDirLister::setNameFilter + * @see nameFilter + */ + void setNameFilter(const TQString& filter); + + /** + * @returns the current namefilter. + * @see setNameFilter + */ + const TQString& nameFilter() const { return dir->nameFilter(); } + + /** + * Sets a list of mimetypes as filter. Only files of those mimetypes + * will be shown. + * + * Example: + * \code + * TQStringList filter; + * filter << "text/html" << "image/png" << "inode/directory"; + * dirOperator->setMimefilter( filter ); + * \endcode + * + * Node: Without the mimetype inode/directory, only files would be shown. + * Call updateDir() to apply it. + * + * @see KDirLister::setMimeFilter + * @see mimeFilter + */ + void setMimeFilter( const TQStringList& mimetypes ); + + /** + * @returns the current mime filter. + */ + TQStringList mimeFilter() const { return dir->mimeFilters(); } + + /** + * Clears both the namefilter and mimetype filter, so that all files and + * directories will be shown. Call updateDir() to apply it. + * + * @see setMimeFilter + * @see setNameFilter + */ + void clearFilter(); + + /** + * @returns the current url + */ + KURL url() const; + + /** + * Sets a new url to list. + * @param clearforward specifies whether the "forward" history should be cleared. + * @param url the URL to set + */ + // ### KDE4: make virtual + void setURL(const KURL& url, bool clearforward); + + /** + * Clears the current selection and attempts to set @p filename + * the current file. filename is just the name, no path or url. + */ + void setCurrentItem( const TQString& filename ); + + /** + * Sets a new KFileView to be used for showing and browsing files. + * Note: this will read the current url() to fill the view. + * + * @see KFileView + * @see KFileIconView + * @see KFileDetailView + * @see KCombiView + * @see view + */ + // ### KDE4: make virtual + void setView(KFileView *view); + + /** + * @returns the currently used view. + * @see setView + */ + KFileView * view() const { return m_fileView; } + + /** + * Returns the widget of the current view. 0L if there is no view/widget. + * (KFileView itself is not a widget.) + */ + TQWidget * viewWidget() const { return m_fileView ? m_fileView->widget() : 0L; } + + /** + * Sets one of the predefined fileviews + * @see KFile::FileView + */ + // ### KDE4: make virtual + void setView(KFile::FileView view); + + /** + * Sets the way to sort files and directories. + */ + void setSorting( TQDir::SortSpec ); + + /** + * @returns the current way of sorting files and directories + */ + TQDir::SortSpec sorting() const { return mySorting; } + + /** + * @returns true if we are displaying the root directory of the current url + */ + bool isRoot() const { return url().path() == TQChar('/'); } + + /** + * @returns the object listing the directory + */ + KDirLister *dirLister() const { return dir; } + + /** + * @returns the progress widget, that is shown during directory listing. + * You can for example reparent() it to put it into a statusbar. + */ + KProgress * progressBar() const; + + /** + * Sets the listing/selection mode for the views, an OR'ed combination of + * @li File + * @li Directory + * @li Files + * @li ExistingOnly + * @li LocalOnly + * + * You cannot mix File and Files of course, as the former means + * single-selection mode, the latter multi-selection. + */ + // ### KDE4: make virtual + void setMode( KFile::Mode m ); + /** + * @returns the listing/selection mode. + */ + KFile::Mode mode() const; + + /** + * Sets a preview-widget to be shown next to the file-view. + * The ownership of @p w is transferred to KDirOperator, so don't + * delete it yourself! + */ + // ### KDE4: make virtual + void setPreviewWidget(const TQWidget *w); + + /** + * @returns a list of all currently selected items. If there is no view, + * then 0L is returned. + */ + const KFileItemList * selectedItems() const { + return ( m_fileView ? m_fileView->selectedItems() : 0L ); + } + + /** + * @returns true if @p item is currently selected, or false otherwise. + */ + inline bool isSelected( const KFileItem *item ) const { + return ( m_fileView ? m_fileView->isSelected( item ) : false ); + } + + /** + * @returns the number of directories in the currently listed url. + * Returns 0 if there is no view. + */ + int numDirs() const; + + /** + * @returns the number of files in the currently listed url. + * Returns 0 if there is no view. + */ + int numFiles() const; + + /** + * @returns a TDECompletion object, containing all filenames and + * directories of the current directory/URL. + * You can use it to insert it into a KLineEdit or KComboBox + * Note: it will only contain files, after prepareCompletionObjects() + * has been called. It will be implicitly called from makeCompletion() + * or makeDirCompletion() + */ + TDECompletion * completionObject() const { + return const_cast( &myCompletion ); + } + + /** + * @returns a TDECompletion object, containing only all directories of the + * current directory/URL. + * You can use it to insert it into a KLineEdit or KComboBox + * Note: it will only contain directories, after + * prepareCompletionObjects() has been called. It will be implicitly + * called from makeCompletion() or makeDirCompletion() + */ + TDECompletion *dirCompletionObject() const { + return const_cast( &myDirCompletion ); + } + + /** + * an accessor to a collection of all available Actions. The actions + * are static, they will be there all the time (no need to connect to + * the signals TDEActionCollection::inserted() or removed(). + * + * There are the following actions: + * + * @li popupMenu : an ActionMenu presenting a popupmenu with all actions + * @li up : changes to the parent directory + * @li back : goes back to the previous directory + * @li forward : goes forward in the history + * @li home : changes to the user's home directory + * @li reload : reloads the current directory + * @li separator : a separator + * @li mkdir : opens a dialog box to create a directory + * @li delete : deletes the selected files/directories + * @li sorting menu : an ActionMenu containing all sort-options + * @li by name : sorts by name + * @li by date : sorts by date + * @li by size : sorts by size + * @li reversed : reverses the sort order + * @li dirs first : sorts directories before files + * @li case insensitive : sorts case insensitively + * @li view menu : an ActionMenu containing all actions concerning the view + * @li short view : shows a simple fileview + * @li detailed view : shows a detailed fileview (dates, permissions ,...) + * @li show hidden : shows hidden files + * @li separate dirs : shows directories in a separate pane + * @li preview : shows a preview next to the fileview + * @li single : hides the separate view for directories or the preview + * @li properties : shows a KPropertiesDialog for the selected files + * + * The short and detailed view are in an exclusive group. The sort-by + * actions are in an exclusive group as well. Also the "separate dirs", + * "preview" and "single" actions are in an exclusive group. + * + * You can e.g. use + * \code + * actionCollection()->action( "up" )->plug( someToolBar ); + * \endcode + * to add a button into a toolbar, which makes the dirOperator change to + * its parent directory. + * + * @returns all available Actions + */ + TDEActionCollection * actionCollection() const { return myActionCollection; } + + /** + * Sets the config object and the to be used group in KDirOperator. This + * will be used to store the view's configuration via + * KFileView::writeConfig() (and for KFileView::readConfig()). + * If you don't set this, the views cannot save and restore their + * configuration. + * + * Usually you call this right after KDirOperator creation so that the view + * instantiation can make use of it already. + * + * Note that KDirOperator does NOT take ownership of that object (typically + * it's TDEGlobal::config() anyway. + * + * @see viewConfig + * @see viewConfigGroup + * @since 3.1 + */ + // ### KDE4: make virtual + void setViewConfig( TDEConfig *config, const TQString& group ); + + /** + * Returns the TDEConfig object used for saving and restoring view's + * configuration. + * @returns the TDEConfig object used for saving and restoring view's + * configuration. + * @since 3.1 + */ + TDEConfig *viewConfig(); + + /** + * Returns the group name used for saving and restoring view's + * configuration. + * @returns the group name used for saving and restoring view's + * configuration. + * @since 3.1 + */ + TQString viewConfigGroup() const; + + /** + * Reads the default settings for a view, i.e. the default KFile::FileView. + * Also reads the sorting and whether hidden files should be shown. + * Note: the default view will not be set - you have to call + * \code + * setView( KFile::Default ) + * \endcode + * to apply it. + * + * @see setView + * @see setViewConfig + * @see writeConfig + */ + virtual void readConfig( TDEConfig *, const TQString& group = TQString::null ); + + /** + * Saves the current settings like sorting, simple or detailed view. + * + * @see readConfig + * @see setViewConfig + */ + virtual void writeConfig( TDEConfig *, const TQString& group = TQString::null ); + + + /** + * This is a KFileDialog specific hack: we want to select directories with + * single click, but not files. But as a generic class, we have to be able + * to select files on single click as well. + * + * This gives us the opportunity to do both. + * + * The default is false, set it to true if you don't want files selected + * with single click. + */ + void setOnlyDoubleClickSelectsFiles( bool enable ); + + /** + * @returns whether files (not directories) should only be select()ed by + * double-clicks. + * @see setOnlyDoubleClickSelectsFiles + */ + bool onlyDoubleClickSelectsFiles() const; + + /** + * Creates the given directory/url. If it is a relative path, + * it will be completed with the current directory. + * If enterDirectory is true, the directory will be entered after a + * successful operation. If unsuccessful, a messagebox will be presented + * to the user. + * @returns true if the directory could be created. + */ + // ### KDE4: make virtual and turn TQString into KURL + bool mkdir( const TQString& directory, bool enterDirectory = true ); + + /** + * Starts and returns a TDEIO::DeleteJob to delete the given @p items. + * + * @param items the list of items to be deleted + * @param ask specifies whether a confirmation dialog should be shown + * @param showProgress passed to the DeleteJob to show a progress dialog + */ + // ### KDE4: make virtual + TDEIO::DeleteJob * del( const KFileItemList& items, + bool ask = true, bool showProgress = true ); + + /** + * Starts and returns a TDEIO::DeleteJob to delete the given @p items. + * + * @param items the list of items to be deleted + * @param parent the parent widget used for the confirmation dialog + * @param ask specifies whether a confirmation dialog should be shown + * @param showProgress passed to the DeleteJob to show a progress dialog + * @since 3.1 + */ + // ### KDE4: make virtual + TDEIO::DeleteJob * del( const KFileItemList& items, TQWidget *parent, + bool ask = true, bool showProgress = true ); + + /** + * Clears the forward and backward history. + */ + void clearHistory(); + + /** + * When going up in the directory hierarchy, KDirOperator can highlight + * the directory that was just left. + * + * I.e. when you go from /home/gis/src to /home/gis, the item "src" will + * be made the current item. + * + * Default is off, because this behavior introduces bug #136630. + * Don't enable until this bug is fixed. + */ + // ### KDE4: make virtual + void setEnableDirHighlighting( bool enable ); + + /** + * @returns whether the last directory will be made the current item + * when going up in the directory hierarchy. + * + * Default is false. + */ + bool dirHighlighting() const; + + /** + * @returns true if we are in directory-only mode, that is, no files are + * shown. + */ + bool dirOnlyMode() const { return dirOnlyMode( myMode ); } + + static bool dirOnlyMode( uint mode ) { + return ( (mode & KFile::Directory) && + (mode & (KFile::File | KFile::Files)) == 0 ); + } + + /** + * Sets up the action menu. + * @param whichActions is an value of OR'd ActionTypes that controls which actions to show in the action menu + */ + void setupMenu(int whichActions); + + /** + * Reimplemented - allow dropping of files if @p b is true + * @param b true if the widget should allow dropping of files + */ + virtual void setAcceptDrops(bool b); + + /** + * Sets the options for dropping files. + * @see KFileView::DropOptions + * @since 3.2 + */ + // ### KDE4: make virtual + void setDropOptions(int options); + + /** + * Starts and returns a TDEIO::CopyJob to trash the given @p items. + * + * @param items the list of items to be trashed + * @param parent the parent widget used for the confirmation dialog + * @param ask specifies whether a confirmation dialog should be shown + * @param showProgress passed to the CopyJob to show a progress dialog + * @since 3.4 + */ + // ### KDE4: make virtual + TDEIO::CopyJob * trash( const KFileItemList& items, TQWidget *parent, + bool ask = true, bool showProgress = true ); + +protected: + /** + * A view factory for creating predefined fileviews. Called internally by setView + * , but you can also call it directly. Reimplement this if you depend on self defined fileviews. + * @param parent is the TQWidget to be set as parent + * @param view is the predefined view to be set, note: this can be several ones OR:ed together. + * @returns the created KFileView + * @see KFileView + * @see KCombiView + * @see KFileDetailView + * @see KFileIconView + * @see KFilePreview + * @see KFile::FileView + * @see setView + */ + virtual KFileView* createView( TQWidget* parent, KFile::FileView view ); + /** + * Sets a custom KDirLister to list directories. + */ + // ### KDE4: make virtual + void setDirLister( KDirLister *lister ); + + virtual void resizeEvent( TQResizeEvent * ); + + /** + * Sets up all the actions. Called from the constructor, you usually + * better not call this. + */ + void setupActions(); + + /** + * Updates the sorting-related actions to comply with the current sorting + * @see sorting + */ + void updateSortActions(); + + /** + * Updates the view-related actions to comply with the current + * KFile::FileView + */ + void updateViewActions(); + + /** + * Sets up the context-menu with all the necessary actions. Called from the + * constructor, you usually don't need to call this. + * @since 3.1 + */ + void setupMenu(); + + /** + * Synchronizes the completion objects with the entries of the + * currently listed url. + * + * Automatically called from makeCompletion() and + * makeDirCompletion() + */ + void prepareCompletionObjects(); + + /** + * Checks if there support from TDEIO::PreviewJob for the currently + * shown files, taking mimeFilter() and nameFilter() into account + * Enables/disables the preview-action accordingly. + */ + bool checkPreviewSupport(); + +public slots: + /** + * Goes one step back in the history and opens that url. + */ + // ### KDE4: make virtual + void back(); + + /** + * Goes one step forward in the history and opens that url. + */ + // ### KDE4: make virtual + void forward(); + + /** + * Enters the home directory. + */ + // ### KDE4: make virtual + void home(); + + /** + * Goes one directory up from the current url. + */ + // ### KDE4: make virtual + void cdUp(); + + /** + * to update the view after changing the settings + */ + void updateDir(); + + /** + * Re-reads the current url. + */ + // ### KDE4: make virtual + void rereadDir(); + + /** + * Opens a dialog to create a new directory. + */ + // ### KDE4: make virtual + void mkdir(); + + /** + * Deletes the currently selected files/directories. + */ + // ### KDE4: make virtual + void deleteSelected(); + + /** + * Enables/disables actions that are selection dependent. Call this e.g. + * when you are about to show a popup menu using some of KDirOperators + * actions. + */ + void updateSelectionDependentActions(); + + /** + * Tries to complete the given string (only completes files). + */ + TQString makeCompletion(const TQString&); + + /** + * Tries to complete the given string (only completes directores). + */ + TQString makeDirCompletion(const TQString&); + + /** + * Trashes the currently selected files/directories. + * @since 3.4 + */ + // ### KDE4: make virtual + void trashSelected(TDEAction::ActivationReason, TQt::ButtonState); + +protected slots: + /** + * Restores the normal cursor after showing the busy-cursor. Also hides + * the progressbar. + */ + void resetCursor(); + + /** + * Called after setURL() to load the directory, update the history, + * etc. + */ + void pathChanged(); + + /** + * Adds a new list of KFileItems to the view + * (coming from KDirLister) + */ + void insertNewFiles(const KFileItemList &newone); + + /** + * Removes the given KFileItem item from the view (usually called from + * KDirLister). + */ + void itemDeleted(KFileItem *); + + /** + * Enters the directory specified by the given @p item. + */ + // ### KDE4: make virtual + void selectDir(const KFileItem *item ); + + /** + * Emits fileSelected( item ) + */ + void selectFile(const KFileItem *item); + + /** + * Emits fileHighlighted( i ) + */ + void highlightFile(const KFileItem* i) { emit fileHighlighted( i ); } + + /** + * Called upon right-click to activate the popupmenu. + */ + virtual void activatedMenu( const KFileItem *, const TQPoint& pos ); + + /** + * Changes sorting to sort by name + */ + void sortByName() { byNameAction->setChecked( true ); } + + /** + * Changes sorting to sort by size + */ + void sortBySize() { bySizeAction->setChecked( true ); } + + /** + * Changes sorting to sort by date + */ + void sortByDate() { byDateAction->setChecked( true ); } + + /** + * Changes sorting to reverse sorting + */ + void sortReversed() { reverseAction->setChecked( !reverseAction->isChecked() ); } + + /** + * Toggles showing directories first / having them sorted like files. + */ + void toggleDirsFirst() { dirsFirstAction->setChecked( !dirsFirstAction->isChecked() ); } + + /** + * Toggles case sensitive / case insensitive sorting + */ + void toggleIgnoreCase() { caseInsensitiveAction->setChecked( !caseInsensitiveAction->isChecked() ); } + + /** + * Tries to make the given @p match as current item in the view and emits + * completion( match ) + */ + void slotCompletionMatch(const TQString& match); + +signals: + void urlEntered(const KURL& ); + void updateInformation(int files, int dirs); + void completion(const TQString&); + void finishedLoading(); + + /** + * Emitted whenever the current fileview is changed, either by an explicit + * call to setView() or by the user selecting a different view thru + * the GUI. + */ + void viewChanged( KFileView * newView ); + + /** + * Emitted when a file is highlighted or generally the selection changes in + * multiselection mode. In the latter case, @p item is 0L. You can access + * the selected items with selectedItems(). + */ + void fileHighlighted( const KFileItem *item ); + void dirActivated( const KFileItem *item ); + void fileSelected( const KFileItem *item ); + /** + * Emitted when files are dropped. Dropping files is disabled by + * default. You need to enable it with setAcceptDrops() + * @param item the item on which the drop occurred or 0. + * @param event the drop event itself. + * @param urls the urls that where dropped. + * @since 3.2 + */ + void dropped(const KFileItem *item, TQDropEvent*event, const KURL::List&urls); +private: + /** + * Contains all URLs you can reach with the back button. + */ + TQPtrStack backStack; + + /** + * Contains all URLs you can reach with the forward button. + */ + TQPtrStack forwardStack; + + KDirLister *dir; + KURL currUrl; + + TDECompletion myCompletion; + TDECompletion myDirCompletion; + bool myCompleteListDirty; + TQDir::SortSpec mySorting; + + /** + * Checks whether we preview support is available for the current + * mimetype/namefilter + */ + bool checkPreviewInternal() const; + + /** + * takes action on the new location. If it's a directory, change + * into it, if it's a file, correct the name, etc. + */ + void checkPath(const TQString& txt, bool takeFiles = false); + + void connectView(KFileView *); + + bool openURL( const KURL& url, bool keep = false, bool reload = false ); + + KFileView *m_fileView; + KFileItemList pendingMimeTypes; + + // the enum KFile::FileView as an int + int m_viewKind; + int defaultView; + + KFile::Mode myMode; + KProgress *progress; + + const TQWidget *myPreview; // temporary pointer for the preview widget + + // actions for the popupmenus + // ### clean up all those -- we have them all in the actionMenu! + TDEActionMenu *actionMenu; + + TDEAction *backAction; + TDEAction *forwardAction; + TDEAction *homeAction; + TDEAction *upAction; + TDEAction *reloadAction; + TDEActionSeparator *actionSeparator; + TDEAction *mkdirAction; + + TDEActionMenu *sortActionMenu; + TDERadioAction *byNameAction; + TDERadioAction *byDateAction; + TDERadioAction *bySizeAction; + TDEToggleAction *reverseAction; + TDEToggleAction *dirsFirstAction; + TDEToggleAction *caseInsensitiveAction; + + TDEActionMenu *viewActionMenu; + TDERadioAction *shortAction; + TDERadioAction *detailedAction; + TDEToggleAction *showHiddenAction; + TDEToggleAction *separateDirsAction; + + TDEActionCollection *myActionCollection; + TDEActionCollection *viewActionCollection; + +private slots: + /** + * @internal + */ + void slotDetailedView(); + void slotSimpleView(); + void slotToggleHidden( bool ); + + void slotSeparateDirs(); + void slotDefaultPreview(); + void togglePreview( bool ); + + void slotSortByName(); + void slotSortBySize(); + void slotSortByDate(); + void slotSortReversed(); + void slotToggleDirsFirst(); + void slotToggleIgnoreCase(); + + void slotStarted(); + void slotProgress( int ); + void slotShowProgress(); + void slotIOFinished(); + void slotCanceled(); + void slotRedirected( const KURL& ); + + void slotViewActionAdded( TDEAction * ); + void slotViewActionRemoved( TDEAction * ); + void slotViewSortingChanged( TQDir::SortSpec ); + + void slotClearView(); + void slotRefreshItems( const KFileItemList& items ); + + void slotProperties(); + + void insertViewDependentActions(); + +private: + static bool isReadable( const KURL& url ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + class KDirOperatorPrivate; + KDirOperatorPrivate *d; +}; + +#endif diff --git a/tdeio/tdeio/kemailsettings.cpp b/tdeio/tdeio/kemailsettings.cpp deleted file mode 100644 index bd46d8708..000000000 --- a/tdeio/tdeio/kemailsettings.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2000 Alex Zepeda - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - -#include "tdeemailsettings.h" - -#include -#include -#include - -class KEMailSettingsPrivate { -public: - KEMailSettingsPrivate() : m_pConfig( 0 ) {} - ~KEMailSettingsPrivate() { delete m_pConfig; } - TDEConfig *m_pConfig; - TQStringList profiles; - TQString m_sDefaultProfile, m_sCurrentProfile; -}; - -TQString KEMailSettings::defaultProfileName() const -{ - return p->m_sDefaultProfile; -} - -TQString KEMailSettings::getSetting(KEMailSettings::Setting s) -{ - p->m_pConfig->setGroup(TQString("PROFILE_")+p->m_sCurrentProfile); - switch (s) { - case ClientProgram: { - return p->m_pConfig->readEntry("EmailClient"); - break; - } - case ClientTerminal: { - return ((p->m_pConfig->readBoolEntry("TerminalClient")) ? TQString("true") : TQString("false") ); - break; - } - case RealName: { - return p->m_pConfig->readEntry("FullName"); - break; - } - case EmailAddress: { - return p->m_pConfig->readEntry("EmailAddress"); - break; - } - case ReplyToAddress: { - return p->m_pConfig->readEntry("ReplyAddr"); - break; - } - case Organization: { - return p->m_pConfig->readEntry("Organization"); - break; - } - case OutServer: { - return p->m_pConfig->readEntry("OutgoingServer"); - break; - } - case OutServerLogin: { - return p->m_pConfig->readEntry("OutgoingUserName"); - break; - } - case OutServerPass: { - return p->m_pConfig->readEntry("OutgoingPassword"); - break; - } - case OutServerType: { - return p->m_pConfig->readEntry("OutgoingServerType"); - break; - } - case OutServerCommand: { - return p->m_pConfig->readEntry("OutgoingCommand"); - break; - } - case OutServerTLS: { - return ((p->m_pConfig->readBoolEntry("OutgoingServerTLS")) ? TQString("true") : TQString("false") ); - break; - } - case InServer: { - return p->m_pConfig->readEntry("IncomingServer"); - break; - } - case InServerLogin: { - return p->m_pConfig->readEntry("IncomingUserName"); - break; - } - case InServerPass: { - return p->m_pConfig->readEntry("IncomingPassword"); - break; - } - case InServerType: { - return p->m_pConfig->readEntry("IncomingServerType"); - break; - } - case InServerMBXType: { - return p->m_pConfig->readEntry("IncomingServerMBXType"); - break; - } - case InServerTLS: { - return ((p->m_pConfig->readBoolEntry("IncomingServerTLS")) ? TQString("true") : TQString("false") ); - break; - } - }; - return TQString::null; -} -void KEMailSettings::setSetting(KEMailSettings::Setting s, const TQString &v) -{ - p->m_pConfig->setGroup(TQString("PROFILE_")+p->m_sCurrentProfile); - switch (s) { - case ClientProgram: { - p->m_pConfig->writePathEntry("EmailClient", v); - break; - } - case ClientTerminal: { - p->m_pConfig->writeEntry("TerminalClient", (v == "true") ? true : false ); - break; - } - case RealName: { - p->m_pConfig->writeEntry("FullName", v); - break; - } - case EmailAddress: { - p->m_pConfig->writeEntry("EmailAddress", v); - break; - } - case ReplyToAddress: { - p->m_pConfig->writeEntry("ReplyAddr", v); - break; - } - case Organization: { - p->m_pConfig->writeEntry("Organization", v); - break; - } - case OutServer: { - p->m_pConfig->writeEntry("OutgoingServer", v); - break; - } - case OutServerLogin: { - p->m_pConfig->writeEntry("OutgoingUserName", v); - break; - } - case OutServerPass: { - p->m_pConfig->writeEntry("OutgoingPassword", v); - break; - } - case OutServerType: { - p->m_pConfig->writeEntry("OutgoingServerType", v); - break; - } - case OutServerCommand: { - p->m_pConfig->writeEntry("OutgoingCommand", v); - break; - } - case OutServerTLS: { - p->m_pConfig->writeEntry("OutgoingServerTLS", (v == "true") ? true : false ); - break; - } - case InServer: { - p->m_pConfig->writeEntry("IncomingServer", v); - break; - } - case InServerLogin: { - p->m_pConfig->writeEntry("IncomingUserName", v); - break; - } - case InServerPass: { - p->m_pConfig->writeEntry("IncomingPassword", v); - break; - } - case InServerType: { - p->m_pConfig->writeEntry("IncomingServerType", v); - break; - } - case InServerMBXType: { - p->m_pConfig->writeEntry("IncomingServerMBXType", v); - break; - } - case InServerTLS: { - p->m_pConfig->writeEntry("IncomingServerTLS", (v == "true") ? true : false ); - break; - } - }; - p->m_pConfig->sync(); -} - -void KEMailSettings::setDefault(const TQString &s) -{ - p->m_pConfig->setGroup("Defaults"); - p->m_pConfig->writeEntry("Profile", s); - p->m_pConfig->sync(); - p->m_sDefaultProfile=s; - -} - -void KEMailSettings::setProfile (const TQString &s) -{ - TQString groupname="PROFILE_"; - groupname.append(s); - p->m_sCurrentProfile=s; - if (!p->m_pConfig->hasGroup(groupname)) { // Create a group if it doesn't exist - p->m_pConfig->setGroup(groupname); - p->m_pConfig->writeEntry("ServerType", TQString::null); - p->m_pConfig->sync(); - p->profiles+=s; - } -} - -TQString KEMailSettings::currentProfileName() const -{ - return p->m_sCurrentProfile; -} - -TQStringList KEMailSettings::profiles() const -{ - return p->profiles; -} - -KEMailSettings::KEMailSettings() -{ - p = new KEMailSettingsPrivate(); - p->m_sCurrentProfile=TQString::null; - - p->m_pConfig = new TDEConfig("emaildefaults"); - - TQStringList groups = p->m_pConfig->groupList(); - for (TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it) { - if ( (*it).left(8) == "PROFILE_" ) - p->profiles+= (*it).mid(8, (*it).length()); - } - - p->m_pConfig->setGroup("Defaults"); - p->m_sDefaultProfile=p->m_pConfig->readEntry("Profile", i18n("Default")); - if (!p->m_sDefaultProfile.isNull()) { - if (!p->m_pConfig->hasGroup(TQString("PROFILE_")+p->m_sDefaultProfile)) - setDefault(i18n("Default")); - else - setDefault(p->m_sDefaultProfile); - } else { - if (p->profiles.count()) { - setDefault(p->profiles[0]); - } else - setDefault(i18n("Default")); - } - setProfile(defaultProfileName()); -} - -KEMailSettings::~KEMailSettings() -{ - delete p; -} diff --git a/tdeio/tdeio/kemailsettings.h b/tdeio/tdeio/kemailsettings.h deleted file mode 100644 index 0ade4520e..000000000 --- a/tdeio/tdeio/kemailsettings.h +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * Copyright (c) 2000 Alex Zepeda - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#ifndef _KEMAILSETTINGS_H -#define _KEMAILSETTINGS_H - -#include -#include - -#include - -class KEMailSettingsPrivate; - - -/** - * This is just a small class to facilitate accessing e-mail settings in - * a sane way, and allowing any program to manage multiple e-mail - * profiles effortlessly - * - * @author Alex Zepeda zipzippy@sonic.net - **/ -class TDEIO_EXPORT KEMailSettings { -public: - /** - * The list of settings that I thought of when I wrote this - * class. Any extra settings thought of later can be accessed - * easily with getExtendedSetting and setExtendedSetting. - * @see getSetting() - * @see setSetting() - * @see getExtendedSetting() - * @see setExtendedSetting() - **/ - enum Setting { - ClientProgram, - ClientTerminal, - RealName, - EmailAddress, - ReplyToAddress, - Organization, - OutServer, - OutServerLogin, - OutServerPass, - OutServerType, - OutServerCommand, - OutServerTLS, - InServer, - InServerLogin, - InServerPass, - InServerType, - InServerMBXType, - InServerTLS - }; - - /** - * The various extensions allowed. - **/ - enum Extension { - POP3, - SMTP, - OTHER - }; - - /** - * Default constructor, just sets things up. - **/ - KEMailSettings(); - - /** - * Default destructor, nothing to see here. - **/ - ~KEMailSettings(); - - /** - * List of profiles available. - * @return the list of profiles - **/ - TQStringList profiles() const; - - /** - * Returns the name of the current profile. - * @returns what profile we're currently using - **/ - TQString currentProfileName() const; - - /** - * Change the current profile. - * @param s the name of the new profile - **/ - void setProfile (const TQString &s); - - /** - * Returns the name of the default profile. - * @returns the name of the one that's currently default TQString::null if none - **/ - TQString defaultProfileName() const; - - /** - * Sets a new default. - * @param def the new default - **/ - void setDefault(const TQString &def); - - /** - * Get one of the predefined "basic" settings. - * @param s the setting to get - * @return the value of the setting, or TQString::null if not - * set - **/ - TQString getSetting(KEMailSettings::Setting s); - - /** - * Set one of the predefined "basic" settings. - * @param s the setting to set - * @param v the new value of the setting, or TQString::null to - * unset - **/ - void setSetting(KEMailSettings::Setting s, const TQString &v); - -private: - KEMailSettingsPrivate *p; -}; - -#endif diff --git a/tdeio/tdeio/kprotocolmanager.cpp b/tdeio/tdeio/kprotocolmanager.cpp deleted file mode 100644 index 65ad393a3..000000000 --- a/tdeio/tdeio/kprotocolmanager.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Torben Weis - Copyright (C) 2000- Waldo Bastain - Copyright (C) 2000- Dawit Alemayehu - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "tdeprotocolmanager.h" - -class -KProtocolManagerPrivate -{ -public: - KProtocolManagerPrivate(); - - ~KProtocolManagerPrivate(); - - TDEConfig *config; - TDEConfig *http_config; - bool init_busy; - KURL url; - TQString protocol; - TQString proxy; - TQString modifiers; - TQString useragent; -}; - -static KProtocolManagerPrivate* d = 0; -static KStaticDeleter kpmpksd; - -KProtocolManagerPrivate::KProtocolManagerPrivate() - :config(0), http_config(0), init_busy(false) -{ - kpmpksd.setObject(d, this); -} - -KProtocolManagerPrivate::~KProtocolManagerPrivate() -{ - delete config; - delete http_config; -} - - -// DEFAULT USERAGENT STRING -#define CFG_DEFAULT_UAGENT(X) \ -TQString("Mozilla/5.0 (compatible; Konqueror/%1.%2%3) TDEHTML/%4.%5.%6 (like Gecko)") \ - .arg(TDE_VERSION_MAJOR).arg(TDE_VERSION_MINOR).arg(X).arg(TDE_VERSION_MAJOR).arg(TDE_VERSION_MINOR).arg(TDE_VERSION_RELEASE) - -void KProtocolManager::reparseConfiguration() -{ - kpmpksd.destructObject(); - - // Force the slave config to re-read its config... - TDEIO::SlaveConfig::self()->reset (); -} - -TDEConfig *KProtocolManager::config() -{ - if (!d) - d = new KProtocolManagerPrivate; - - if (!d->config) - { - d->config = new TDEConfig("tdeioslaverc", true, false); - } - return d->config; -} - -TDEConfig *KProtocolManager::http_config() -{ - if (!d) - d = new KProtocolManagerPrivate; - - if (!d->http_config) - { - d->http_config = new TDEConfig("tdeio_httprc", false, false); - } - return d->http_config; -} - -/*=============================== TIMEOUT SETTINGS ==========================*/ - -int KProtocolManager::readTimeout() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - int val = cfg->readNumEntry( "ReadTimeout", DEFAULT_READ_TIMEOUT ); - return QMAX(MIN_TIMEOUT_VALUE, val); -} - -int KProtocolManager::connectTimeout() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - int val = cfg->readNumEntry( "ConnectTimeout", DEFAULT_CONNECT_TIMEOUT ); - return QMAX(MIN_TIMEOUT_VALUE, val); -} - -int KProtocolManager::proxyConnectTimeout() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - int val = cfg->readNumEntry( "ProxyConnectTimeout", DEFAULT_PROXY_CONNECT_TIMEOUT ); - return QMAX(MIN_TIMEOUT_VALUE, val); -} - -int KProtocolManager::responseTimeout() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - int val = cfg->readNumEntry( "ResponseTimeout", DEFAULT_RESPONSE_TIMEOUT ); - return QMAX(MIN_TIMEOUT_VALUE, val); -} - -/*========================== PROXY SETTINGS =================================*/ - -bool KProtocolManager::useProxy() -{ - return proxyType() != NoProxy; -} - -bool KProtocolManager::useReverseProxy() -{ - TDEConfig *cfg = config(); - cfg->setGroup( "Proxy Settings" ); - return cfg->readBoolEntry("ReversedException", false); -} - -KProtocolManager::ProxyType KProtocolManager::proxyType() -{ - TDEConfig *cfg = config(); - cfg->setGroup( "Proxy Settings" ); - return static_cast(cfg->readNumEntry( "ProxyType" )); -} - -KProtocolManager::ProxyAuthMode KProtocolManager::proxyAuthMode() -{ - TDEConfig *cfg = config(); - cfg->setGroup( "Proxy Settings" ); - return static_cast(cfg->readNumEntry( "AuthMode" )); -} - -/*========================== CACHING =====================================*/ - -bool KProtocolManager::useCache() -{ - TDEConfig *cfg = http_config(); - return cfg->readBoolEntry( "UseCache", true ); -} - -TDEIO::CacheControl KProtocolManager::cacheControl() -{ - TDEConfig *cfg = http_config(); - TQString tmp = cfg->readEntry("cache"); - if (tmp.isEmpty()) - return DEFAULT_CACHE_CONTROL; - return TDEIO::parseCacheControl(tmp); -} - -TQString KProtocolManager::cacheDir() -{ - TDEConfig *cfg = http_config(); - return cfg->readPathEntry("CacheDir", TDEGlobal::dirs()->saveLocation("cache","http")); -} - -int KProtocolManager::maxCacheAge() -{ - TDEConfig *cfg = http_config(); - return cfg->readNumEntry( "MaxCacheAge", DEFAULT_MAX_CACHE_AGE ); // 14 days -} - -int KProtocolManager::maxCacheSize() -{ - TDEConfig *cfg = http_config(); - return cfg->readNumEntry( "MaxCacheSize", DEFAULT_MAX_CACHE_SIZE ); // 5 MB -} - -TQString KProtocolManager::noProxyForRaw() -{ - TDEConfig *cfg = config(); - cfg->setGroup( "Proxy Settings" ); - - return cfg->readEntry( "NoProxyFor" ); -} - -TQString KProtocolManager::noProxyFor() -{ - TQString noProxy = noProxyForRaw(); - if (proxyType() == EnvVarProxy) - noProxy = TQString::fromLocal8Bit(getenv(noProxy.local8Bit())); - - return noProxy; -} - -TQString KProtocolManager::proxyFor( const TQString& protocol ) -{ - TQString scheme = protocol.lower(); - - if (scheme == "webdav") - scheme = "http"; - else if (scheme == "webdavs") - scheme = "https"; - - TDEConfig *cfg = config(); - cfg->setGroup( "Proxy Settings" ); - return cfg->readEntry( scheme + "Proxy" ); -} - -TQString KProtocolManager::proxyForURL( const KURL &url ) -{ - TQString proxy; - ProxyType pt = proxyType(); - - switch (pt) - { - case PACProxy: - case WPADProxy: - if (!url.host().isEmpty()) - { - KURL u (url); - TQString p = u.protocol().lower(); - - // webdav is a KDE specific protocol. Look up proxy - // information using HTTP instead... - if ( p == "webdav" ) - { - p = "http"; - u.setProtocol( p ); - } - else if ( p == "webdavs" ) - { - p = "https"; - u.setProtocol( p ); - } - - if ( p.startsWith("http") || p == "ftp" || p == "gopher" ) - DCOPRef( "kded", "proxyscout" ).call( "proxyForURL", u ).get( proxy ); - } - break; - case EnvVarProxy: - proxy = TQString(TQString::fromLocal8Bit(getenv(proxyFor(url.protocol()).local8Bit()))).stripWhiteSpace(); - break; - case ManualProxy: - proxy = proxyFor( url.protocol() ); - break; - case NoProxy: - default: - break; - } - - return (proxy.isEmpty() ? TQString::fromLatin1("DIRECT") : proxy); -} - -void KProtocolManager::badProxy( const TQString &proxy ) -{ - DCOPRef( "kded", "proxyscout" ).send( "blackListProxy", proxy ); -} - -/* - Domain suffix match. E.g. return true if host is "cuzco.inka.de" and - nplist is "inka.de,hadiko.de" or if host is "localhost" and nplist is - "localhost". -*/ -static bool revmatch(const char *host, const char *nplist) -{ - if (host == 0) - return false; - - const char *hptr = host + strlen( host ) - 1; - const char *nptr = nplist + strlen( nplist ) - 1; - const char *shptr = hptr; - - while ( nptr >= nplist ) - { - if ( *hptr != *nptr ) - { - hptr = shptr; - - // Try to find another domain or host in the list - while(--nptr>=nplist && *nptr!=',' && *nptr!=' ') ; - - // Strip out multiple spaces and commas - while(--nptr>=nplist && (*nptr==',' || *nptr==' ')) ; - } - else - { - if ( nptr==nplist || nptr[-1]==',' || nptr[-1]==' ') - return true; - if ( hptr == host ) // e.g. revmatch("bugs.kde.org","mybugs.kde.org") - return false; - - hptr--; - nptr--; - } - } - - return false; -} - -TQString KProtocolManager::slaveProtocol(const KURL &url, TQString &proxy) -{ - if (url.hasSubURL()) // We don't want the suburl's protocol - { - KURL::List list = KURL::split(url); - KURL::List::Iterator it = list.fromLast(); - return slaveProtocol(*it, proxy); - } - - if (!d) - d = new KProtocolManagerPrivate; - - if (d->url == url) - { - proxy = d->proxy; - return d->protocol; - } - - if (useProxy()) - { - proxy = proxyForURL(url); - if ((proxy != "DIRECT") && (!proxy.isEmpty())) - { - bool isRevMatch = false; - KProtocolManager::ProxyType type = proxyType(); - bool useRevProxy = ((type == ManualProxy) && useReverseProxy()); - - TQString noProxy; - // Check no proxy information iff the proxy type is either - // ManualProxy or EnvVarProxy - if ( (type == ManualProxy) || (type == EnvVarProxy) ) - noProxy = noProxyFor(); - - if (!noProxy.isEmpty()) - { - TQString qhost = url.host().lower(); - const char *host = qhost.latin1(); - TQString qno_proxy = noProxy.stripWhiteSpace().lower(); - const char *no_proxy = qno_proxy.latin1(); - isRevMatch = revmatch(host, no_proxy); - - // If no match is found and the request url has a port - // number, try the combination of "host:port". This allows - // users to enter host:port in the No-proxy-For list. - if (!isRevMatch && url.port() > 0) - { - qhost += ':' + TQString::number (url.port()); - host = qhost.latin1(); - isRevMatch = revmatch (host, no_proxy); - } - - // If the hostname does not contain a dot, check if - // is part of noProxy. - if (!isRevMatch && host && (strchr(host, '.') == NULL)) - isRevMatch = revmatch("", no_proxy); - } - - if ( (!useRevProxy && !isRevMatch) || (useRevProxy && isRevMatch) ) - { - d->url = proxy; - if ( d->url.isValid() ) - { - // The idea behind slave protocols is not applicable to http - // and webdav protocols. - TQString protocol = url.protocol().lower(); - if (protocol.startsWith("http") || protocol.startsWith("webdav")) - d->protocol = protocol; - else - { - d->protocol = d->url.protocol(); - kdDebug () << "slaveProtocol: " << d->protocol << endl; - } - - d->url = url; - d->proxy = proxy; - return d->protocol; - } - } - } - } - - d->url = url; - d->proxy = proxy = TQString::null; - d->protocol = url.protocol(); - return d->protocol; -} - -/*================================= USER-AGENT SETTINGS =====================*/ - -TQString KProtocolManager::userAgentForHost( const TQString& hostname ) -{ - TQString sendUserAgent = TDEIO::SlaveConfig::self()->configData("http", hostname.lower(), "SendUserAgent").lower(); - if (sendUserAgent == "false") - return TQString::null; - - TQString useragent = TDEIO::SlaveConfig::self()->configData("http", hostname.lower(), "UserAgent"); - - // Return the default user-agent if none is specified - // for the requested host. - if (useragent.isEmpty()) - return defaultUserAgent(); - - return useragent; -} - -TQString KProtocolManager::defaultUserAgent( ) -{ - TQString modifiers = TDEIO::SlaveConfig::self()->configData("http", TQString::null, "UserAgentKeys"); - return defaultUserAgent(modifiers); -} - -TQString KProtocolManager::defaultUserAgent( const TQString &_modifiers ) -{ - if (!d) - d = new KProtocolManagerPrivate; - - TQString modifiers = _modifiers.lower(); - if (modifiers.isEmpty()) - modifiers = DEFAULT_USER_AGENT_KEYS; - - if (d->modifiers == modifiers) - return d->useragent; - - TQString supp; - struct utsname nam; - if( uname(&nam) >= 0 ) - { - if( modifiers.contains('o') ) - { - supp += TQString("; %1").arg(nam.sysname); - if ( modifiers.contains('v') ) - supp += TQString(" %1").arg(nam.release); - } - if( modifiers.contains('p') ) - { - // TODO: determine this value instead of hardcoding it... - supp += TQString::fromLatin1("; X11"); - } - if( modifiers.contains('m') ) - { - supp += TQString("; %1").arg(nam.machine); - } - if( modifiers.contains('l') ) - { - TQStringList languageList = TDEGlobal::locale()->languageList(); - TQStringList::Iterator it = languageList.find( TQString::fromLatin1("C") ); - if( it != languageList.end() ) - { - if( languageList.contains( TQString::fromLatin1("en") ) > 0 ) - languageList.remove( it ); - else - (*it) = TQString::fromLatin1("en"); - } - if( languageList.count() ) - supp += TQString("; %1").arg(languageList.join(", ")); - } - } - d->modifiers = modifiers; - d->useragent = CFG_DEFAULT_UAGENT(supp); - return d->useragent; -} - -/*==================================== OTHERS ===============================*/ - -bool KProtocolManager::markPartial() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - return cfg->readBoolEntry( "MarkPartial", true ); -} - -int KProtocolManager::minimumKeepSize() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - return cfg->readNumEntry( "MinimumKeepSize", - DEFAULT_MINIMUM_KEEP_SIZE ); // 5000 byte -} - -bool KProtocolManager::autoResume() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - return cfg->readBoolEntry( "AutoResume", false ); -} - -bool KProtocolManager::persistentConnections() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - return cfg->readBoolEntry( "PersistentConnections", true ); -} - -bool KProtocolManager::persistentProxyConnection() -{ - TDEConfig *cfg = config(); - cfg->setGroup( TQString::null ); - return cfg->readBoolEntry( "PersistentProxyConnection", false ); -} - -TQString KProtocolManager::proxyConfigScript() -{ - TDEConfig *cfg = config(); - cfg->setGroup( "Proxy Settings" ); - return cfg->readEntry( "Proxy Config Script" ); -} diff --git a/tdeio/tdeio/kprotocolmanager.h b/tdeio/tdeio/kprotocolmanager.h deleted file mode 100644 index 95106f90d..000000000 --- a/tdeio/tdeio/kprotocolmanager.h +++ /dev/null @@ -1,389 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Torben Weis - Copyright (C) 2000- Waldo Bastain - Copyright (C) 2000- Dawit Alemayehu - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ -#ifndef __kprotocolmanager_h__ -#define __kprotocolmanager_h__ - -#include - -#include -#include - -/** @deprecated Use KProtocolManager::defaultUserAgent() instead. */ -#define DEFAULT_USERAGENT_STRING "" - -class TDEConfig; - -/** - * Provides information about I/O (Internet, etc.) settings chosen/set - * by the end user. - * - * KProtocolManager has a heap of static functions that allows only read - * access to KDE's IO related settings. These include proxy, cache, file - * transfer resumption, timeout and user-agent related settings. - * - * The information provided by this class is generic enough to be applicable - * to any application that makes use of KDE's IO sub-system. Note that this - * mean the proxy, timeout etc. settings are saved in a separate user-specific - * config file and not in the config file of the application. - * - * Original author: - * @author Torben Weis - * - * Revised by: - * @author Waldo Bastain - * @author Dawit Alemayehu - * @see KPAC - */ -class TDEIO_EXPORT KProtocolManager -{ -public: - - -/*=========================== USER-AGENT SETTINGS ===========================*/ - - - /** - * Returns the default user-agent string. - * - * @return the default user-agent string - */ - static TQString defaultUserAgent(); - - /** - * Returns the default user-agent value. - * - * @param keys can be any of the following: - * @li 'o' Show OS - * @li 'v' Show OS Version - * @li 'p' Show platform - * @li 'm' Show machine architecture - * @li 'l' Show language - * @return the default user-agent value with the given @p keys - */ - static TQString defaultUserAgent(const TQString &keys); - - /** - * Returns the userAgent string configured for the - * specified host. - * - * If hostname is not found or is empty (i.e. "" or - * TQString::null) this function will return the default - * user agent. - * - * @param hostname name of the host - * @return specified userAgent string - */ - static TQString userAgentForHost( const TQString &hostname ); - - -/*=========================== TIMEOUT CONFIG ================================*/ - - - /** - * Returns the preferred timeout value for reading from - * remote connections in seconds. - * - * @return timeout value for remote connection in secs. - */ - static int readTimeout(); - - /** - * Returns the preferred timeout value for remote connections - * in seconds. - * - * @return timeout value for remote connection in secs. - */ - static int connectTimeout(); - - /** - * Returns the preferred timeout value for proxy connections - * in seconds. - * - * @return timeout value for proxy connection in secs. - */ - static int proxyConnectTimeout(); - - /** - * Returns the preferred response timeout value for - * remote connecting in seconds. - * - * @return timeout value for remote connection in seconds. - */ - static int responseTimeout(); - - -/*=============================== PROXY CONFIG ==============================*/ - - - /** - * Returns true if the user specified a proxy server to make connections. - * - * @see slaveProtocol, proxyForURL, proxyFor - */ - static bool useProxy(); - - /** - * Returns true if the proxy settings should apply to the list - * returned by @ref noProxyFor. - * - * Normally addresses listed in the noProxyFor list are not routed - * through a proxy server. However, if this function returns true, - * then all addresses listed in the noProxyFor list are to be routed - * through a proxy server where as those that are not should bypass it. - * - * This function as well as @ref noProxyFor only apply when @ref proxyType - * is @p ManualProxy. - * - * @see proxyForURL, proxyFor, slaveProtocol - */ - static bool useReverseProxy(); - - /** - * Types of proxy configuration - * @li NoProxy - No proxy is used - * @li ManualProxy - Proxies are manually configured - * @li PACProxy - A Proxy configuration URL has been given - * @li WPADProxy - A proxy should be automatically discovered - * @li EnvVarProxy - Use the proxy values set through environment variables. - */ - enum ProxyType - { - NoProxy, - ManualProxy, - PACProxy, - WPADProxy, - EnvVarProxy - }; - - /** - * Returns the type of proxy configuration that is used. - * - * @see ProxyType - */ - static ProxyType proxyType(); - - /** - * Proxy authorization modes. - * - * @li Prompt - Ask for authorization as needed - * @li Automatic - Use auto login as defined in .kionetrc files. - * - * NOTE: .kionetrc files have the same format as ftp .netrc files. - * Please note the use of .kionetrc files is highly discouraged since - * password is stored in clear text. For future releases the ability - * to store preset password for proxy servers will probably be supported - * through KWallet integration. - */ - enum ProxyAuthMode - { - Prompt, - Automatic - }; - - /** - * Returns the way proxy authorization should be handled. - * - * @see ProxyAuthMode - */ - static ProxyAuthMode proxyAuthMode(); - - /** - * Returns a comma-separated list of hostnames or partial - * host-names that should bypass any proxy settings. - * - * This function as well as @ref useReverseProxy only apply - * when @ref proxyType is @p ManualProxy. - * - * @see useReverseProxy, proxyFor, proxyForURL, slaveProtocol - */ - static TQString noProxyFor(); - - /** - * Same as above except the environment variable name - * is returned instead of the variable value when - * @ref proxyType is @p EnvVarProxy. - * - * @see noProxyFor - * @since 3.5.x - */ - static TQString noProxyForRaw(); - - /** - * Returns the proxy server address for a given protocol. - * - * NOTE: This function does not take the @ref useReverseProxy() - * settings into account. - * - * @see useReverseProxy, slaveProtocol - * @param protocol the protocol whose proxy info is needed - * @returns the proxy server address if one is available, - * or TQString::null if not available - */ - static TQString proxyFor( const TQString& protocol ); - - /** - * Returns the proxy server address for a given URL. - * - * If @ref proxyType returns Automatic, an external service - * called KPAC (a kded module) is used to determine the proxy - * server. Otherwise, @ref proxyFor is invoked to determine - * whether the URL needs to be routed through a proxy server. - * - * NOTE: This function does not take the @ref useReverseProxy() - * or the @ref noProxyFor() settings into account. - * - * @see useReverseProxy, slaveProtocol, noProxyFor - * @param url the URL whose proxy info is needed - * @returns the proxy server address or the text "DIRECT" - * if no proxying is needed for the given address. - */ - static TQString proxyForURL( const KURL& url ); - - /** - * Marks this proxy as bad (down). It will not be used for the - * next 30 minutes. (The script may supply an alternate proxy) - * @param proxy the proxy to mark as bad (as URL) - */ - static void badProxy( const TQString & proxy ); - - /** - * Returns the URL of the script for automatic proxy configuration. - * @return the proxy configuration script - */ - static TQString proxyConfigScript(); - - -/*========================== CACHE CONFIG ===================================*/ - - - /** - * Returns true/false to indicate whether a cache - * should be used - * - * @return true to use the cache, false otherwisea - */ - static bool useCache(); - - /** - * Returns the maximum age in seconds cached files should be - * kept before they are deleted as necessary. - * - * @return the maximum cache age in seconds - */ - static int maxCacheAge(); - - /** - * Returns the maximum size that can be used for caching. - * - * By default this function returns the DEFAULT_MAX_CACHE_SIZE - * value as defined in http_slave_defaults.h. Not that the - * value returned is in bytes, hence a value of 5120 would mean - * 5 Kb. - * - * @return the maximum cache size in bytes - */ - static int maxCacheSize(); // Maximum cache size in Kb. - - /** - * The directory which contains the cache files. - * @return the directory that contains the cache files - */ - static TQString cacheDir(); - - /** - * Returns the Cache control directive to be used. - * @return the cache control value - */ - static TDEIO::CacheControl cacheControl(); - - -/*============================ DOWNLOAD CONFIG ==============================*/ - - /** - * Returns true if partial downloads should be - * automatically resumed. - * @return true to resume partial downloads - */ - static bool autoResume(); - - /** - * Returns true if partial downloads should be marked - * with a ".part" extension. - * @return true if partial downloads should get an ".part" extension - */ - static bool markPartial(); - - /** - * Returns the minimum file size for keeping aborted - * downloads. - * - * Any data downloaded that does not meet this minimum - * requirement will simply be discarded. The default size - * is 5 KB. - * - * @return the minimum keep size for aborted downloads in bytes - */ - static int minimumKeepSize(); - - - /*============================ NETWORK CONNECTIONS ==========================*/ - /** - * Returns true if proxy connections should be persistent. - * @return true if proxy connections should be persistent - * @since 3.1 - */ - static bool persistentProxyConnection(); - - /** - * Returns true if connections should be persistent - * @return true if the connections should be persistent - */ - static bool persistentConnections(); - -/*=============================== OTHERS ====================================*/ - - - /** - * Force a reload of the general config file of - * io-slaves ( tdeioslaverc). - */ - static void reparseConfiguration(); - - /** - * Return the protocol to use in order to handle the given @p url - * It's usually the same, except that FTP, when handled by a proxy, - * needs an HTTP ioslave. - * - * When a proxy is to be used, proxy contains the URL for the proxy. - * @param url the url to check - * @param proxy the URL of the proxy to use - * @return the slave protocol (e.g. 'http'), can be null if unknown - */ - static TQString slaveProtocol(const KURL &url, TQString &proxy); - - /** - * @internal - * (Shared with SlaveConfig) - */ - static TDEConfig *config(); -private: - static TDEConfig *http_config(); -}; -#endif diff --git a/tdeio/tdeio/tdeemailsettings.cpp b/tdeio/tdeio/tdeemailsettings.cpp new file mode 100644 index 000000000..bd46d8708 --- /dev/null +++ b/tdeio/tdeio/tdeemailsettings.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2000 Alex Zepeda + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +#include "tdeemailsettings.h" + +#include +#include +#include + +class KEMailSettingsPrivate { +public: + KEMailSettingsPrivate() : m_pConfig( 0 ) {} + ~KEMailSettingsPrivate() { delete m_pConfig; } + TDEConfig *m_pConfig; + TQStringList profiles; + TQString m_sDefaultProfile, m_sCurrentProfile; +}; + +TQString KEMailSettings::defaultProfileName() const +{ + return p->m_sDefaultProfile; +} + +TQString KEMailSettings::getSetting(KEMailSettings::Setting s) +{ + p->m_pConfig->setGroup(TQString("PROFILE_")+p->m_sCurrentProfile); + switch (s) { + case ClientProgram: { + return p->m_pConfig->readEntry("EmailClient"); + break; + } + case ClientTerminal: { + return ((p->m_pConfig->readBoolEntry("TerminalClient")) ? TQString("true") : TQString("false") ); + break; + } + case RealName: { + return p->m_pConfig->readEntry("FullName"); + break; + } + case EmailAddress: { + return p->m_pConfig->readEntry("EmailAddress"); + break; + } + case ReplyToAddress: { + return p->m_pConfig->readEntry("ReplyAddr"); + break; + } + case Organization: { + return p->m_pConfig->readEntry("Organization"); + break; + } + case OutServer: { + return p->m_pConfig->readEntry("OutgoingServer"); + break; + } + case OutServerLogin: { + return p->m_pConfig->readEntry("OutgoingUserName"); + break; + } + case OutServerPass: { + return p->m_pConfig->readEntry("OutgoingPassword"); + break; + } + case OutServerType: { + return p->m_pConfig->readEntry("OutgoingServerType"); + break; + } + case OutServerCommand: { + return p->m_pConfig->readEntry("OutgoingCommand"); + break; + } + case OutServerTLS: { + return ((p->m_pConfig->readBoolEntry("OutgoingServerTLS")) ? TQString("true") : TQString("false") ); + break; + } + case InServer: { + return p->m_pConfig->readEntry("IncomingServer"); + break; + } + case InServerLogin: { + return p->m_pConfig->readEntry("IncomingUserName"); + break; + } + case InServerPass: { + return p->m_pConfig->readEntry("IncomingPassword"); + break; + } + case InServerType: { + return p->m_pConfig->readEntry("IncomingServerType"); + break; + } + case InServerMBXType: { + return p->m_pConfig->readEntry("IncomingServerMBXType"); + break; + } + case InServerTLS: { + return ((p->m_pConfig->readBoolEntry("IncomingServerTLS")) ? TQString("true") : TQString("false") ); + break; + } + }; + return TQString::null; +} +void KEMailSettings::setSetting(KEMailSettings::Setting s, const TQString &v) +{ + p->m_pConfig->setGroup(TQString("PROFILE_")+p->m_sCurrentProfile); + switch (s) { + case ClientProgram: { + p->m_pConfig->writePathEntry("EmailClient", v); + break; + } + case ClientTerminal: { + p->m_pConfig->writeEntry("TerminalClient", (v == "true") ? true : false ); + break; + } + case RealName: { + p->m_pConfig->writeEntry("FullName", v); + break; + } + case EmailAddress: { + p->m_pConfig->writeEntry("EmailAddress", v); + break; + } + case ReplyToAddress: { + p->m_pConfig->writeEntry("ReplyAddr", v); + break; + } + case Organization: { + p->m_pConfig->writeEntry("Organization", v); + break; + } + case OutServer: { + p->m_pConfig->writeEntry("OutgoingServer", v); + break; + } + case OutServerLogin: { + p->m_pConfig->writeEntry("OutgoingUserName", v); + break; + } + case OutServerPass: { + p->m_pConfig->writeEntry("OutgoingPassword", v); + break; + } + case OutServerType: { + p->m_pConfig->writeEntry("OutgoingServerType", v); + break; + } + case OutServerCommand: { + p->m_pConfig->writeEntry("OutgoingCommand", v); + break; + } + case OutServerTLS: { + p->m_pConfig->writeEntry("OutgoingServerTLS", (v == "true") ? true : false ); + break; + } + case InServer: { + p->m_pConfig->writeEntry("IncomingServer", v); + break; + } + case InServerLogin: { + p->m_pConfig->writeEntry("IncomingUserName", v); + break; + } + case InServerPass: { + p->m_pConfig->writeEntry("IncomingPassword", v); + break; + } + case InServerType: { + p->m_pConfig->writeEntry("IncomingServerType", v); + break; + } + case InServerMBXType: { + p->m_pConfig->writeEntry("IncomingServerMBXType", v); + break; + } + case InServerTLS: { + p->m_pConfig->writeEntry("IncomingServerTLS", (v == "true") ? true : false ); + break; + } + }; + p->m_pConfig->sync(); +} + +void KEMailSettings::setDefault(const TQString &s) +{ + p->m_pConfig->setGroup("Defaults"); + p->m_pConfig->writeEntry("Profile", s); + p->m_pConfig->sync(); + p->m_sDefaultProfile=s; + +} + +void KEMailSettings::setProfile (const TQString &s) +{ + TQString groupname="PROFILE_"; + groupname.append(s); + p->m_sCurrentProfile=s; + if (!p->m_pConfig->hasGroup(groupname)) { // Create a group if it doesn't exist + p->m_pConfig->setGroup(groupname); + p->m_pConfig->writeEntry("ServerType", TQString::null); + p->m_pConfig->sync(); + p->profiles+=s; + } +} + +TQString KEMailSettings::currentProfileName() const +{ + return p->m_sCurrentProfile; +} + +TQStringList KEMailSettings::profiles() const +{ + return p->profiles; +} + +KEMailSettings::KEMailSettings() +{ + p = new KEMailSettingsPrivate(); + p->m_sCurrentProfile=TQString::null; + + p->m_pConfig = new TDEConfig("emaildefaults"); + + TQStringList groups = p->m_pConfig->groupList(); + for (TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it) { + if ( (*it).left(8) == "PROFILE_" ) + p->profiles+= (*it).mid(8, (*it).length()); + } + + p->m_pConfig->setGroup("Defaults"); + p->m_sDefaultProfile=p->m_pConfig->readEntry("Profile", i18n("Default")); + if (!p->m_sDefaultProfile.isNull()) { + if (!p->m_pConfig->hasGroup(TQString("PROFILE_")+p->m_sDefaultProfile)) + setDefault(i18n("Default")); + else + setDefault(p->m_sDefaultProfile); + } else { + if (p->profiles.count()) { + setDefault(p->profiles[0]); + } else + setDefault(i18n("Default")); + } + setProfile(defaultProfileName()); +} + +KEMailSettings::~KEMailSettings() +{ + delete p; +} diff --git a/tdeio/tdeio/tdeemailsettings.h b/tdeio/tdeio/tdeemailsettings.h new file mode 100644 index 000000000..0ade4520e --- /dev/null +++ b/tdeio/tdeio/tdeemailsettings.h @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 2000 Alex Zepeda + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef _KEMAILSETTINGS_H +#define _KEMAILSETTINGS_H + +#include +#include + +#include + +class KEMailSettingsPrivate; + + +/** + * This is just a small class to facilitate accessing e-mail settings in + * a sane way, and allowing any program to manage multiple e-mail + * profiles effortlessly + * + * @author Alex Zepeda zipzippy@sonic.net + **/ +class TDEIO_EXPORT KEMailSettings { +public: + /** + * The list of settings that I thought of when I wrote this + * class. Any extra settings thought of later can be accessed + * easily with getExtendedSetting and setExtendedSetting. + * @see getSetting() + * @see setSetting() + * @see getExtendedSetting() + * @see setExtendedSetting() + **/ + enum Setting { + ClientProgram, + ClientTerminal, + RealName, + EmailAddress, + ReplyToAddress, + Organization, + OutServer, + OutServerLogin, + OutServerPass, + OutServerType, + OutServerCommand, + OutServerTLS, + InServer, + InServerLogin, + InServerPass, + InServerType, + InServerMBXType, + InServerTLS + }; + + /** + * The various extensions allowed. + **/ + enum Extension { + POP3, + SMTP, + OTHER + }; + + /** + * Default constructor, just sets things up. + **/ + KEMailSettings(); + + /** + * Default destructor, nothing to see here. + **/ + ~KEMailSettings(); + + /** + * List of profiles available. + * @return the list of profiles + **/ + TQStringList profiles() const; + + /** + * Returns the name of the current profile. + * @returns what profile we're currently using + **/ + TQString currentProfileName() const; + + /** + * Change the current profile. + * @param s the name of the new profile + **/ + void setProfile (const TQString &s); + + /** + * Returns the name of the default profile. + * @returns the name of the one that's currently default TQString::null if none + **/ + TQString defaultProfileName() const; + + /** + * Sets a new default. + * @param def the new default + **/ + void setDefault(const TQString &def); + + /** + * Get one of the predefined "basic" settings. + * @param s the setting to get + * @return the value of the setting, or TQString::null if not + * set + **/ + TQString getSetting(KEMailSettings::Setting s); + + /** + * Set one of the predefined "basic" settings. + * @param s the setting to set + * @param v the new value of the setting, or TQString::null to + * unset + **/ + void setSetting(KEMailSettings::Setting s, const TQString &v); + +private: + KEMailSettingsPrivate *p; +}; + +#endif diff --git a/tdeio/tdeio/tdeprotocolmanager.cpp b/tdeio/tdeio/tdeprotocolmanager.cpp new file mode 100644 index 000000000..65ad393a3 --- /dev/null +++ b/tdeio/tdeio/tdeprotocolmanager.cpp @@ -0,0 +1,534 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Torben Weis + Copyright (C) 2000- Waldo Bastain + Copyright (C) 2000- Dawit Alemayehu + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tdeprotocolmanager.h" + +class +KProtocolManagerPrivate +{ +public: + KProtocolManagerPrivate(); + + ~KProtocolManagerPrivate(); + + TDEConfig *config; + TDEConfig *http_config; + bool init_busy; + KURL url; + TQString protocol; + TQString proxy; + TQString modifiers; + TQString useragent; +}; + +static KProtocolManagerPrivate* d = 0; +static KStaticDeleter kpmpksd; + +KProtocolManagerPrivate::KProtocolManagerPrivate() + :config(0), http_config(0), init_busy(false) +{ + kpmpksd.setObject(d, this); +} + +KProtocolManagerPrivate::~KProtocolManagerPrivate() +{ + delete config; + delete http_config; +} + + +// DEFAULT USERAGENT STRING +#define CFG_DEFAULT_UAGENT(X) \ +TQString("Mozilla/5.0 (compatible; Konqueror/%1.%2%3) TDEHTML/%4.%5.%6 (like Gecko)") \ + .arg(TDE_VERSION_MAJOR).arg(TDE_VERSION_MINOR).arg(X).arg(TDE_VERSION_MAJOR).arg(TDE_VERSION_MINOR).arg(TDE_VERSION_RELEASE) + +void KProtocolManager::reparseConfiguration() +{ + kpmpksd.destructObject(); + + // Force the slave config to re-read its config... + TDEIO::SlaveConfig::self()->reset (); +} + +TDEConfig *KProtocolManager::config() +{ + if (!d) + d = new KProtocolManagerPrivate; + + if (!d->config) + { + d->config = new TDEConfig("tdeioslaverc", true, false); + } + return d->config; +} + +TDEConfig *KProtocolManager::http_config() +{ + if (!d) + d = new KProtocolManagerPrivate; + + if (!d->http_config) + { + d->http_config = new TDEConfig("tdeio_httprc", false, false); + } + return d->http_config; +} + +/*=============================== TIMEOUT SETTINGS ==========================*/ + +int KProtocolManager::readTimeout() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + int val = cfg->readNumEntry( "ReadTimeout", DEFAULT_READ_TIMEOUT ); + return QMAX(MIN_TIMEOUT_VALUE, val); +} + +int KProtocolManager::connectTimeout() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + int val = cfg->readNumEntry( "ConnectTimeout", DEFAULT_CONNECT_TIMEOUT ); + return QMAX(MIN_TIMEOUT_VALUE, val); +} + +int KProtocolManager::proxyConnectTimeout() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + int val = cfg->readNumEntry( "ProxyConnectTimeout", DEFAULT_PROXY_CONNECT_TIMEOUT ); + return QMAX(MIN_TIMEOUT_VALUE, val); +} + +int KProtocolManager::responseTimeout() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + int val = cfg->readNumEntry( "ResponseTimeout", DEFAULT_RESPONSE_TIMEOUT ); + return QMAX(MIN_TIMEOUT_VALUE, val); +} + +/*========================== PROXY SETTINGS =================================*/ + +bool KProtocolManager::useProxy() +{ + return proxyType() != NoProxy; +} + +bool KProtocolManager::useReverseProxy() +{ + TDEConfig *cfg = config(); + cfg->setGroup( "Proxy Settings" ); + return cfg->readBoolEntry("ReversedException", false); +} + +KProtocolManager::ProxyType KProtocolManager::proxyType() +{ + TDEConfig *cfg = config(); + cfg->setGroup( "Proxy Settings" ); + return static_cast(cfg->readNumEntry( "ProxyType" )); +} + +KProtocolManager::ProxyAuthMode KProtocolManager::proxyAuthMode() +{ + TDEConfig *cfg = config(); + cfg->setGroup( "Proxy Settings" ); + return static_cast(cfg->readNumEntry( "AuthMode" )); +} + +/*========================== CACHING =====================================*/ + +bool KProtocolManager::useCache() +{ + TDEConfig *cfg = http_config(); + return cfg->readBoolEntry( "UseCache", true ); +} + +TDEIO::CacheControl KProtocolManager::cacheControl() +{ + TDEConfig *cfg = http_config(); + TQString tmp = cfg->readEntry("cache"); + if (tmp.isEmpty()) + return DEFAULT_CACHE_CONTROL; + return TDEIO::parseCacheControl(tmp); +} + +TQString KProtocolManager::cacheDir() +{ + TDEConfig *cfg = http_config(); + return cfg->readPathEntry("CacheDir", TDEGlobal::dirs()->saveLocation("cache","http")); +} + +int KProtocolManager::maxCacheAge() +{ + TDEConfig *cfg = http_config(); + return cfg->readNumEntry( "MaxCacheAge", DEFAULT_MAX_CACHE_AGE ); // 14 days +} + +int KProtocolManager::maxCacheSize() +{ + TDEConfig *cfg = http_config(); + return cfg->readNumEntry( "MaxCacheSize", DEFAULT_MAX_CACHE_SIZE ); // 5 MB +} + +TQString KProtocolManager::noProxyForRaw() +{ + TDEConfig *cfg = config(); + cfg->setGroup( "Proxy Settings" ); + + return cfg->readEntry( "NoProxyFor" ); +} + +TQString KProtocolManager::noProxyFor() +{ + TQString noProxy = noProxyForRaw(); + if (proxyType() == EnvVarProxy) + noProxy = TQString::fromLocal8Bit(getenv(noProxy.local8Bit())); + + return noProxy; +} + +TQString KProtocolManager::proxyFor( const TQString& protocol ) +{ + TQString scheme = protocol.lower(); + + if (scheme == "webdav") + scheme = "http"; + else if (scheme == "webdavs") + scheme = "https"; + + TDEConfig *cfg = config(); + cfg->setGroup( "Proxy Settings" ); + return cfg->readEntry( scheme + "Proxy" ); +} + +TQString KProtocolManager::proxyForURL( const KURL &url ) +{ + TQString proxy; + ProxyType pt = proxyType(); + + switch (pt) + { + case PACProxy: + case WPADProxy: + if (!url.host().isEmpty()) + { + KURL u (url); + TQString p = u.protocol().lower(); + + // webdav is a KDE specific protocol. Look up proxy + // information using HTTP instead... + if ( p == "webdav" ) + { + p = "http"; + u.setProtocol( p ); + } + else if ( p == "webdavs" ) + { + p = "https"; + u.setProtocol( p ); + } + + if ( p.startsWith("http") || p == "ftp" || p == "gopher" ) + DCOPRef( "kded", "proxyscout" ).call( "proxyForURL", u ).get( proxy ); + } + break; + case EnvVarProxy: + proxy = TQString(TQString::fromLocal8Bit(getenv(proxyFor(url.protocol()).local8Bit()))).stripWhiteSpace(); + break; + case ManualProxy: + proxy = proxyFor( url.protocol() ); + break; + case NoProxy: + default: + break; + } + + return (proxy.isEmpty() ? TQString::fromLatin1("DIRECT") : proxy); +} + +void KProtocolManager::badProxy( const TQString &proxy ) +{ + DCOPRef( "kded", "proxyscout" ).send( "blackListProxy", proxy ); +} + +/* + Domain suffix match. E.g. return true if host is "cuzco.inka.de" and + nplist is "inka.de,hadiko.de" or if host is "localhost" and nplist is + "localhost". +*/ +static bool revmatch(const char *host, const char *nplist) +{ + if (host == 0) + return false; + + const char *hptr = host + strlen( host ) - 1; + const char *nptr = nplist + strlen( nplist ) - 1; + const char *shptr = hptr; + + while ( nptr >= nplist ) + { + if ( *hptr != *nptr ) + { + hptr = shptr; + + // Try to find another domain or host in the list + while(--nptr>=nplist && *nptr!=',' && *nptr!=' ') ; + + // Strip out multiple spaces and commas + while(--nptr>=nplist && (*nptr==',' || *nptr==' ')) ; + } + else + { + if ( nptr==nplist || nptr[-1]==',' || nptr[-1]==' ') + return true; + if ( hptr == host ) // e.g. revmatch("bugs.kde.org","mybugs.kde.org") + return false; + + hptr--; + nptr--; + } + } + + return false; +} + +TQString KProtocolManager::slaveProtocol(const KURL &url, TQString &proxy) +{ + if (url.hasSubURL()) // We don't want the suburl's protocol + { + KURL::List list = KURL::split(url); + KURL::List::Iterator it = list.fromLast(); + return slaveProtocol(*it, proxy); + } + + if (!d) + d = new KProtocolManagerPrivate; + + if (d->url == url) + { + proxy = d->proxy; + return d->protocol; + } + + if (useProxy()) + { + proxy = proxyForURL(url); + if ((proxy != "DIRECT") && (!proxy.isEmpty())) + { + bool isRevMatch = false; + KProtocolManager::ProxyType type = proxyType(); + bool useRevProxy = ((type == ManualProxy) && useReverseProxy()); + + TQString noProxy; + // Check no proxy information iff the proxy type is either + // ManualProxy or EnvVarProxy + if ( (type == ManualProxy) || (type == EnvVarProxy) ) + noProxy = noProxyFor(); + + if (!noProxy.isEmpty()) + { + TQString qhost = url.host().lower(); + const char *host = qhost.latin1(); + TQString qno_proxy = noProxy.stripWhiteSpace().lower(); + const char *no_proxy = qno_proxy.latin1(); + isRevMatch = revmatch(host, no_proxy); + + // If no match is found and the request url has a port + // number, try the combination of "host:port". This allows + // users to enter host:port in the No-proxy-For list. + if (!isRevMatch && url.port() > 0) + { + qhost += ':' + TQString::number (url.port()); + host = qhost.latin1(); + isRevMatch = revmatch (host, no_proxy); + } + + // If the hostname does not contain a dot, check if + // is part of noProxy. + if (!isRevMatch && host && (strchr(host, '.') == NULL)) + isRevMatch = revmatch("", no_proxy); + } + + if ( (!useRevProxy && !isRevMatch) || (useRevProxy && isRevMatch) ) + { + d->url = proxy; + if ( d->url.isValid() ) + { + // The idea behind slave protocols is not applicable to http + // and webdav protocols. + TQString protocol = url.protocol().lower(); + if (protocol.startsWith("http") || protocol.startsWith("webdav")) + d->protocol = protocol; + else + { + d->protocol = d->url.protocol(); + kdDebug () << "slaveProtocol: " << d->protocol << endl; + } + + d->url = url; + d->proxy = proxy; + return d->protocol; + } + } + } + } + + d->url = url; + d->proxy = proxy = TQString::null; + d->protocol = url.protocol(); + return d->protocol; +} + +/*================================= USER-AGENT SETTINGS =====================*/ + +TQString KProtocolManager::userAgentForHost( const TQString& hostname ) +{ + TQString sendUserAgent = TDEIO::SlaveConfig::self()->configData("http", hostname.lower(), "SendUserAgent").lower(); + if (sendUserAgent == "false") + return TQString::null; + + TQString useragent = TDEIO::SlaveConfig::self()->configData("http", hostname.lower(), "UserAgent"); + + // Return the default user-agent if none is specified + // for the requested host. + if (useragent.isEmpty()) + return defaultUserAgent(); + + return useragent; +} + +TQString KProtocolManager::defaultUserAgent( ) +{ + TQString modifiers = TDEIO::SlaveConfig::self()->configData("http", TQString::null, "UserAgentKeys"); + return defaultUserAgent(modifiers); +} + +TQString KProtocolManager::defaultUserAgent( const TQString &_modifiers ) +{ + if (!d) + d = new KProtocolManagerPrivate; + + TQString modifiers = _modifiers.lower(); + if (modifiers.isEmpty()) + modifiers = DEFAULT_USER_AGENT_KEYS; + + if (d->modifiers == modifiers) + return d->useragent; + + TQString supp; + struct utsname nam; + if( uname(&nam) >= 0 ) + { + if( modifiers.contains('o') ) + { + supp += TQString("; %1").arg(nam.sysname); + if ( modifiers.contains('v') ) + supp += TQString(" %1").arg(nam.release); + } + if( modifiers.contains('p') ) + { + // TODO: determine this value instead of hardcoding it... + supp += TQString::fromLatin1("; X11"); + } + if( modifiers.contains('m') ) + { + supp += TQString("; %1").arg(nam.machine); + } + if( modifiers.contains('l') ) + { + TQStringList languageList = TDEGlobal::locale()->languageList(); + TQStringList::Iterator it = languageList.find( TQString::fromLatin1("C") ); + if( it != languageList.end() ) + { + if( languageList.contains( TQString::fromLatin1("en") ) > 0 ) + languageList.remove( it ); + else + (*it) = TQString::fromLatin1("en"); + } + if( languageList.count() ) + supp += TQString("; %1").arg(languageList.join(", ")); + } + } + d->modifiers = modifiers; + d->useragent = CFG_DEFAULT_UAGENT(supp); + return d->useragent; +} + +/*==================================== OTHERS ===============================*/ + +bool KProtocolManager::markPartial() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + return cfg->readBoolEntry( "MarkPartial", true ); +} + +int KProtocolManager::minimumKeepSize() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + return cfg->readNumEntry( "MinimumKeepSize", + DEFAULT_MINIMUM_KEEP_SIZE ); // 5000 byte +} + +bool KProtocolManager::autoResume() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + return cfg->readBoolEntry( "AutoResume", false ); +} + +bool KProtocolManager::persistentConnections() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + return cfg->readBoolEntry( "PersistentConnections", true ); +} + +bool KProtocolManager::persistentProxyConnection() +{ + TDEConfig *cfg = config(); + cfg->setGroup( TQString::null ); + return cfg->readBoolEntry( "PersistentProxyConnection", false ); +} + +TQString KProtocolManager::proxyConfigScript() +{ + TDEConfig *cfg = config(); + cfg->setGroup( "Proxy Settings" ); + return cfg->readEntry( "Proxy Config Script" ); +} diff --git a/tdeio/tdeio/tdeprotocolmanager.h b/tdeio/tdeio/tdeprotocolmanager.h new file mode 100644 index 000000000..95106f90d --- /dev/null +++ b/tdeio/tdeio/tdeprotocolmanager.h @@ -0,0 +1,389 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Torben Weis + Copyright (C) 2000- Waldo Bastain + Copyright (C) 2000- Dawit Alemayehu + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef __kprotocolmanager_h__ +#define __kprotocolmanager_h__ + +#include + +#include +#include + +/** @deprecated Use KProtocolManager::defaultUserAgent() instead. */ +#define DEFAULT_USERAGENT_STRING "" + +class TDEConfig; + +/** + * Provides information about I/O (Internet, etc.) settings chosen/set + * by the end user. + * + * KProtocolManager has a heap of static functions that allows only read + * access to KDE's IO related settings. These include proxy, cache, file + * transfer resumption, timeout and user-agent related settings. + * + * The information provided by this class is generic enough to be applicable + * to any application that makes use of KDE's IO sub-system. Note that this + * mean the proxy, timeout etc. settings are saved in a separate user-specific + * config file and not in the config file of the application. + * + * Original author: + * @author Torben Weis + * + * Revised by: + * @author Waldo Bastain + * @author Dawit Alemayehu + * @see KPAC + */ +class TDEIO_EXPORT KProtocolManager +{ +public: + + +/*=========================== USER-AGENT SETTINGS ===========================*/ + + + /** + * Returns the default user-agent string. + * + * @return the default user-agent string + */ + static TQString defaultUserAgent(); + + /** + * Returns the default user-agent value. + * + * @param keys can be any of the following: + * @li 'o' Show OS + * @li 'v' Show OS Version + * @li 'p' Show platform + * @li 'm' Show machine architecture + * @li 'l' Show language + * @return the default user-agent value with the given @p keys + */ + static TQString defaultUserAgent(const TQString &keys); + + /** + * Returns the userAgent string configured for the + * specified host. + * + * If hostname is not found or is empty (i.e. "" or + * TQString::null) this function will return the default + * user agent. + * + * @param hostname name of the host + * @return specified userAgent string + */ + static TQString userAgentForHost( const TQString &hostname ); + + +/*=========================== TIMEOUT CONFIG ================================*/ + + + /** + * Returns the preferred timeout value for reading from + * remote connections in seconds. + * + * @return timeout value for remote connection in secs. + */ + static int readTimeout(); + + /** + * Returns the preferred timeout value for remote connections + * in seconds. + * + * @return timeout value for remote connection in secs. + */ + static int connectTimeout(); + + /** + * Returns the preferred timeout value for proxy connections + * in seconds. + * + * @return timeout value for proxy connection in secs. + */ + static int proxyConnectTimeout(); + + /** + * Returns the preferred response timeout value for + * remote connecting in seconds. + * + * @return timeout value for remote connection in seconds. + */ + static int responseTimeout(); + + +/*=============================== PROXY CONFIG ==============================*/ + + + /** + * Returns true if the user specified a proxy server to make connections. + * + * @see slaveProtocol, proxyForURL, proxyFor + */ + static bool useProxy(); + + /** + * Returns true if the proxy settings should apply to the list + * returned by @ref noProxyFor. + * + * Normally addresses listed in the noProxyFor list are not routed + * through a proxy server. However, if this function returns true, + * then all addresses listed in the noProxyFor list are to be routed + * through a proxy server where as those that are not should bypass it. + * + * This function as well as @ref noProxyFor only apply when @ref proxyType + * is @p ManualProxy. + * + * @see proxyForURL, proxyFor, slaveProtocol + */ + static bool useReverseProxy(); + + /** + * Types of proxy configuration + * @li NoProxy - No proxy is used + * @li ManualProxy - Proxies are manually configured + * @li PACProxy - A Proxy configuration URL has been given + * @li WPADProxy - A proxy should be automatically discovered + * @li EnvVarProxy - Use the proxy values set through environment variables. + */ + enum ProxyType + { + NoProxy, + ManualProxy, + PACProxy, + WPADProxy, + EnvVarProxy + }; + + /** + * Returns the type of proxy configuration that is used. + * + * @see ProxyType + */ + static ProxyType proxyType(); + + /** + * Proxy authorization modes. + * + * @li Prompt - Ask for authorization as needed + * @li Automatic - Use auto login as defined in .kionetrc files. + * + * NOTE: .kionetrc files have the same format as ftp .netrc files. + * Please note the use of .kionetrc files is highly discouraged since + * password is stored in clear text. For future releases the ability + * to store preset password for proxy servers will probably be supported + * through KWallet integration. + */ + enum ProxyAuthMode + { + Prompt, + Automatic + }; + + /** + * Returns the way proxy authorization should be handled. + * + * @see ProxyAuthMode + */ + static ProxyAuthMode proxyAuthMode(); + + /** + * Returns a comma-separated list of hostnames or partial + * host-names that should bypass any proxy settings. + * + * This function as well as @ref useReverseProxy only apply + * when @ref proxyType is @p ManualProxy. + * + * @see useReverseProxy, proxyFor, proxyForURL, slaveProtocol + */ + static TQString noProxyFor(); + + /** + * Same as above except the environment variable name + * is returned instead of the variable value when + * @ref proxyType is @p EnvVarProxy. + * + * @see noProxyFor + * @since 3.5.x + */ + static TQString noProxyForRaw(); + + /** + * Returns the proxy server address for a given protocol. + * + * NOTE: This function does not take the @ref useReverseProxy() + * settings into account. + * + * @see useReverseProxy, slaveProtocol + * @param protocol the protocol whose proxy info is needed + * @returns the proxy server address if one is available, + * or TQString::null if not available + */ + static TQString proxyFor( const TQString& protocol ); + + /** + * Returns the proxy server address for a given URL. + * + * If @ref proxyType returns Automatic, an external service + * called KPAC (a kded module) is used to determine the proxy + * server. Otherwise, @ref proxyFor is invoked to determine + * whether the URL needs to be routed through a proxy server. + * + * NOTE: This function does not take the @ref useReverseProxy() + * or the @ref noProxyFor() settings into account. + * + * @see useReverseProxy, slaveProtocol, noProxyFor + * @param url the URL whose proxy info is needed + * @returns the proxy server address or the text "DIRECT" + * if no proxying is needed for the given address. + */ + static TQString proxyForURL( const KURL& url ); + + /** + * Marks this proxy as bad (down). It will not be used for the + * next 30 minutes. (The script may supply an alternate proxy) + * @param proxy the proxy to mark as bad (as URL) + */ + static void badProxy( const TQString & proxy ); + + /** + * Returns the URL of the script for automatic proxy configuration. + * @return the proxy configuration script + */ + static TQString proxyConfigScript(); + + +/*========================== CACHE CONFIG ===================================*/ + + + /** + * Returns true/false to indicate whether a cache + * should be used + * + * @return true to use the cache, false otherwisea + */ + static bool useCache(); + + /** + * Returns the maximum age in seconds cached files should be + * kept before they are deleted as necessary. + * + * @return the maximum cache age in seconds + */ + static int maxCacheAge(); + + /** + * Returns the maximum size that can be used for caching. + * + * By default this function returns the DEFAULT_MAX_CACHE_SIZE + * value as defined in http_slave_defaults.h. Not that the + * value returned is in bytes, hence a value of 5120 would mean + * 5 Kb. + * + * @return the maximum cache size in bytes + */ + static int maxCacheSize(); // Maximum cache size in Kb. + + /** + * The directory which contains the cache files. + * @return the directory that contains the cache files + */ + static TQString cacheDir(); + + /** + * Returns the Cache control directive to be used. + * @return the cache control value + */ + static TDEIO::CacheControl cacheControl(); + + +/*============================ DOWNLOAD CONFIG ==============================*/ + + /** + * Returns true if partial downloads should be + * automatically resumed. + * @return true to resume partial downloads + */ + static bool autoResume(); + + /** + * Returns true if partial downloads should be marked + * with a ".part" extension. + * @return true if partial downloads should get an ".part" extension + */ + static bool markPartial(); + + /** + * Returns the minimum file size for keeping aborted + * downloads. + * + * Any data downloaded that does not meet this minimum + * requirement will simply be discarded. The default size + * is 5 KB. + * + * @return the minimum keep size for aborted downloads in bytes + */ + static int minimumKeepSize(); + + + /*============================ NETWORK CONNECTIONS ==========================*/ + /** + * Returns true if proxy connections should be persistent. + * @return true if proxy connections should be persistent + * @since 3.1 + */ + static bool persistentProxyConnection(); + + /** + * Returns true if connections should be persistent + * @return true if the connections should be persistent + */ + static bool persistentConnections(); + +/*=============================== OTHERS ====================================*/ + + + /** + * Force a reload of the general config file of + * io-slaves ( tdeioslaverc). + */ + static void reparseConfiguration(); + + /** + * Return the protocol to use in order to handle the given @p url + * It's usually the same, except that FTP, when handled by a proxy, + * needs an HTTP ioslave. + * + * When a proxy is to be used, proxy contains the URL for the proxy. + * @param url the url to check + * @param proxy the URL of the proxy to use + * @return the slave protocol (e.g. 'http'), can be null if unknown + */ + static TQString slaveProtocol(const KURL &url, TQString &proxy); + + /** + * @internal + * (Shared with SlaveConfig) + */ + static TDEConfig *config(); +private: + static TDEConfig *http_config(); +}; +#endif -- cgit v1.2.1