• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • utils
filedialog.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  utils/filedialog.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2009 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 
34 #include <config-kleopatra.h>
35 
36 #include "filedialog.h"
37 
38 #ifdef QT_NO_FILEDIALOG
39 #include <KFileDialog>
40 #include <KUrl>
41 #include <QTextStream>
42 #endif
43 #include <QFileDialog>
44 #include <QDir>
45 #include <QMap>
46 
47 using namespace Kleo;
48 
49 namespace {
50  typedef QMap<QString,QString> Map;
51  Q_GLOBAL_STATIC( Map, dir_id_2_dir_map )
52 }
53 
54 static QString dir( const QString & id ) {
55  const QString dir = (*dir_id_2_dir_map())[id];
56  if ( dir.isEmpty() )
57  return QDir::homePath();
58  else
59  return dir;
60 }
61 
62 static void update( const QString & fname, const QString & id ) {
63  if ( !fname.isEmpty() )
64  (*dir_id_2_dir_map())[ id ] = QFileInfo( fname ).absolutePath();
65 }
66 
67 #ifdef QT_NO_FILEDIALOG
68 static QString qt2KdeFilter(const QString &f)
69 {
70  QString filter;
71  QTextStream str(&filter, QIODevice::WriteOnly);
72  QStringList list(f.split(";;").replaceInStrings("/", "\\/"));
73  QStringList::const_iterator it(list.begin()),
74  end(list.end());
75  bool first=true;
76 
77  for(; it!=end; ++it)
78  {
79  int ob=(*it).lastIndexOf('('),
80  cb=(*it).lastIndexOf(')');
81 
82  if(-1!=cb && ob<cb)
83  {
84  if(first)
85  first=false;
86  else
87  str << '\n';
88  str << (*it).mid(ob+1, (cb-ob)-1) << '|' << (*it).mid(0, ob);
89  }
90  }
91 
92  return filter;
93 }
94 #endif
95 
96 QString FileDialog::getExistingDirectory( QWidget * parent, const QString & caption, const QString & dirID ) {
97 #ifndef QT_NO_FILEDIALOG
98  const QString fname = QFileDialog::getExistingDirectory( parent, caption, dir( dirID ) );
99 #else
100  const QString fname = KFileDialog::getExistingDirectory( dir( dirID ), parent, caption );
101 #endif
102  update( fname, dirID );
103  return fname;
104 }
105 
106 QString FileDialog::getOpenFileName( QWidget * parent, const QString & caption, const QString & dirID, const QString & filter ) {
107 #ifndef QT_NO_FILEDIALOG
108  const QString fname = QFileDialog::getOpenFileName( parent, caption, dir( dirID ), filter );
109 #else
110  const QString fname = KFileDialog::getOpenFileName( dir( dirID ), qt2KdeFilter( filter ), parent, caption );
111 #endif
112  update( fname, dirID );
113  return fname;
114 }
115 
116 QStringList FileDialog::getOpenFileNames( QWidget * parent, const QString & caption, const QString & dirID, const QString & filter ) {
117 #ifndef QT_NO_FILEDIALOG
118  const QStringList files = QFileDialog::getOpenFileNames( parent, caption, dir( dirID ), filter );
119 #else
120  const QStringList files = KFileDialog::getOpenFileNames( dir( dirID ), qt2KdeFilter( filter ), parent, caption );
121 #endif
122  if ( !files.empty() )
123  update( files.front(), dirID );
124  return files;
125 }
126 
127 QString FileDialog::getSaveFileName( QWidget * parent, const QString & caption, const QString & dirID, const QString & filter ) {
128 #ifndef QT_NO_FILEDIALOG
129  const QString fname = QFileDialog::getSaveFileName( parent, caption, dir( dirID ), filter );
130 #else
131  const QString fname = KFileDialog::getSaveFileName( dirID.isEmpty() ? KUrl() : dir( dirID ), qt2KdeFilter( filter ), parent, caption );
132 #endif
133  update( fname, dirID );
134  return fname;
135 }
136 
137 QString FileDialog::getSaveFileNameEx( QWidget * parent, const QString & caption, const QString & dirID, const QString & proposedFileName, const QString & filter ) {
138  if ( proposedFileName.isEmpty() )
139 #ifndef QT_NO_FILEDIALOG
140  return getSaveFileName( parent, caption, dirID, filter );
141  const QString fname = QFileDialog::getSaveFileName( parent, caption, QDir( dir( dirID ) ).filePath( proposedFileName ), filter );
142 #else
143  return getSaveFileName( parent, caption, QString(), filter );
144  const QString fname = KFileDialog::getSaveFileName( QDir( dir( dirID ) ).filePath( proposedFileName ), qt2KdeFilter( filter ), parent, caption );
145 #endif
146  update( fname, dirID );
147  return fname;
148 }
QWidget
QFileDialog::getExistingDirectory
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFlags< QFileDialog::Option > options)
Kleo::FileDialog::getOpenFileName
QString getOpenFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:106
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QMap
Definition: signingcertificateselectiondialog.h:41
QDir::homePath
QString homePath()
QList::const_iterator
QTextStream
QList::empty
bool empty() const
Kleo::FileDialog::getExistingDirectory
QString getExistingDirectory(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString())
Definition: filedialog.cpp:96
QString::isEmpty
bool isEmpty() const
Kleo::FileDialog::getOpenFileNames
QStringList getOpenFileNames(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:116
QList::front
T & front()
QStringList::replaceInStrings
QStringList & replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs)
QString
QStringList
QFileInfo
Kleo::FileDialog::getSaveFileName
QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:127
Kleo::FileDialog::getSaveFileNameEx
QString getSaveFileNameEx(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &proposedFileName=QString(), const QString &filter=QString())
Definition: filedialog.cpp:137
QDir
dir
static QString dir(const QString &id)
Definition: filedialog.cpp:54
update
static void update(const QString &fname, const QString &id)
Definition: filedialog.cpp:62
QFileDialog::getSaveFileName
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
QtConcurrent::filter
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
QFileDialog::getOpenFileName
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
QFileInfo::absolutePath
QString absolutePath() const
QFileDialog::getOpenFileNames
QStringList getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
filedialog.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal