diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
commit | a6d58bb6052ac8cb01805a48c4ad2f129126116f (patch) | |
tree | dd867a099fcbb263a8009a9fb22695b87855dad6 /src/kvirc/ui/kvi_filedialog.cpp | |
download | kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip |
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/kvirc/ui/kvi_filedialog.cpp')
-rw-r--r-- | src/kvirc/ui/kvi_filedialog.cpp | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/src/kvirc/ui/kvi_filedialog.cpp b/src/kvirc/ui/kvi_filedialog.cpp new file mode 100644 index 0000000..99f9c16 --- /dev/null +++ b/src/kvirc/ui/kvi_filedialog.cpp @@ -0,0 +1,229 @@ +// +// File : kvi_filedialog.cpp +// Creation date : Mon Nov 20 2000 12:20:42 CEST by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2001 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +#define __KVIRC__ +#include "kvi_filedialog.h" +#include "kvi_mediatype.h" +#include "kvi_iconmanager.h" +#include "kvi_locale.h" +#include "kvi_app.h" +#include "kvi_fileutils.h" +#include "kvi_frame.h" +#include "kvi_qstring.h" + +#include <qdir.h> +#include "kvi_tal_tooltip.h" +#include <qmessagebox.h> + +extern KviMediaManager * g_pMediaManager; + + +KviFileDialog::KviFileDialog(const QString &dirName, const QString &filter, + QWidget *parent, const char *name, bool modal) +: KviTalFileDialog(dirName,filter,parent,name,modal) +{ + + setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_FOLDER))); + +} + +KviFileDialog::~KviFileDialog() +{ +} + + +/* +void KviFileDialog::goKvirc() +{ + + KviStr tmp; + g_pApp->getLocalKvircDirectory(tmp,KviApp::None); + setDir(QDir(tmp.ptr())); + +} + +void KviFileDialog::goHome() +{ + + setDir(QDir::home()); + +} +*/ + + + +bool KviFileDialog::askForOpenFileName(QString &buffer,const QString &caption,const QString &initial,const QString &filter,bool showHidden, bool showNative,QWidget* parent) +{ +#ifdef COMPILE_ON_WINDOWS + if(showNative) + { + buffer=QFileDialog::getOpenFileName(initial,filter,parent,"open_file_name_dialog",caption); + KviFileUtils::adjustFilePath(buffer); + return !buffer.isEmpty(); + } +#endif + KviFileDialog * d = new KviFileDialog(initial,filter,parent,"open_file_name_dialog",true); + d->setCaption(caption); + d->setMode(QFileDialog::ExistingFile); + //d->setShowHiddenFiles(showHidden); + if(d->exec() == QDialog::Accepted) + { + buffer = d->selectedFile(); + KviFileUtils::adjustFilePath(buffer); + delete d; + return !buffer.isEmpty(); + } + delete d; + return false; +} + + +bool KviFileDialog::askForSaveFileName(QString &buffer,const QString & caption,const QString &initial,const QString &filter,bool showHidden,bool bConfirmOverwrite,bool showNative,QWidget* parent) +{ + #ifdef COMPILE_ON_WINDOWS + if (showNative) + { + while (1) + { + buffer=QFileDialog::getSaveFileName(initial,filter,parent,"save_file_name_dialog",caption); + KviFileUtils::adjustFilePath(buffer); + //return !buffer.isEmpty(); + if(buffer.isEmpty()) return false; + if(!bConfirmOverwrite) return true; + // Check for the file existence + if(!KviFileUtils::fileExists(buffer)) return true; + QString tmp; + KviQString::sprintf(tmp,__tr2qs("The file %s already exists.<br>Do you wish to overwrite it?"),buffer.utf8().data()); + switch(QMessageBox::information(parent,__tr2qs("File Exists - KVIrc"),tmp,QMessageBox::Yes,QMessageBox::No | QMessageBox::Default,QMessageBox::Cancel | QMessageBox::Escape)) + { + case QMessageBox::Cancel: return false; break; + case QMessageBox::Yes: return true; break; + } + + } + + + } + #endif + + + KviFileDialog * d = new KviFileDialog(initial,filter,parent,"save_file_name_dialog",true); + d->setCaption(caption); + d->setMode(QFileDialog::AnyFile); + //d->setShowHiddenFiles(showHidden); + + while(d->exec() == QDialog::Accepted) + { + buffer = d->selectedFile(); + KviFileUtils::adjustFilePath(buffer); + + if(!buffer.isEmpty()) + { + if(!bConfirmOverwrite) + { + delete d; + return true; + } + // Check for the file existence + if(KviFileUtils::fileExists(buffer)) + { + QString tmp; + KviQString::sprintf(tmp,__tr2qs("The file %s already exists.<br>Do you wish to overwrite it?"),buffer.utf8().data()); + switch(QMessageBox::information(d,__tr2qs("File Exists - KVIrc"),tmp,QMessageBox::Yes,QMessageBox::No | QMessageBox::Default,QMessageBox::Cancel | QMessageBox::Escape)) + { + case QMessageBox::Cancel: delete d; return false; break; + case QMessageBox::Yes: delete d; return true; break; + } + } else { + delete d; + return true; // ok...file not exists + } + } else { + delete d; + return false; // empty buffer + } + } + + delete d; + return false; + +} + +bool KviFileDialog::askForDirectoryName(QString &buffer,const QString & caption,const QString & initial,const char * filter,bool showHidden,bool showNative,QWidget* parent) +{ +#ifdef COMPILE_ON_WINDOWS + if(showNative) + { + buffer = QFileDialog::getExistingDirectory(initial,parent,"open_file_name_dialog",caption); + return !buffer.isEmpty(); + } +#else + #ifdef COMPILE_KDE_SUPPORT + // the KDE based dir selection dialog is now quite nice + buffer = KFileDialog::getExistingDirectory(initial,parent,caption); + return !buffer.isEmpty(); + #endif +#endif + + KviFileDialog * d = new KviFileDialog(initial, + filter,parent,"directory_name_dialog",true); + d->setCaption(caption); + d->setMode(QFileDialog::Directory); + //d->setShowHiddenFiles(showHidden); + if(d->exec() == QDialog::Accepted) + { + buffer = d->selectedFile(); + KviFileUtils::adjustFilePath(buffer); + delete d; + return !buffer.isEmpty(); + } + delete d; + + return false; +} + + +bool KviFileDialog::askForOpenFileNames(QStringList &buffer,const QString & caption,const QString & initial,const char * filter,bool showHidden,bool showNative,QWidget* parent) +{ + #ifdef COMPILE_ON_WINDOWS + if (showNative) + { + buffer=QFileDialog::getOpenFileNames(filter,initial,parent,"open_file_name_dialog",caption); + return (buffer.count()>0); + } + + #endif + KviFileDialog * d = new KviFileDialog(initial,filter ? QString(filter) : QString::null,parent,"open_file_names_dialog",true); + d->setCaption(caption); + d->setMode(QFileDialog::ExistingFiles); + //d->setShowHiddenFiles(showHidden); + if(d->exec() == QDialog::Accepted) + { + buffer = d->selectedFiles(); + delete d; + return (buffer.count() > 0); + } + delete d; + return false; +} + + +#include "kvi_filedialog.moc" |