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

kleopatra

  • sources
  • kde-4.12
  • 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 
44 #include <QMap>
45 
46 using namespace Kleo;
47 
48 namespace {
49  typedef QMap<QString,QString> Map;
50  Q_GLOBAL_STATIC( Map, dir_id_2_dir_map )
51 }
52 
53 static QString dir( const QString & id ) {
54  const QString dir = (*dir_id_2_dir_map())[id];
55  if ( dir.isEmpty() )
56  return QDir::homePath();
57  else
58  return dir;
59 }
60 
61 static void update( const QString & fname, const QString & id ) {
62  if ( !fname.isEmpty() )
63  (*dir_id_2_dir_map())[ id ] = QFileInfo( fname ).absolutePath();
64 }
65 
66 #ifdef QT_NO_FILEDIALOG
67 static QString qt2KdeFilter(const QString &f)
68 {
69  QString filter;
70  QTextStream str(&filter, QIODevice::WriteOnly);
71  QStringList list(f.split(";;").replaceInStrings("/", "\\/"));
72  QStringList::const_iterator it(list.begin()),
73  end(list.end());
74  bool first=true;
75 
76  for(; it!=end; ++it)
77  {
78  int ob=(*it).lastIndexOf('('),
79  cb=(*it).lastIndexOf(')');
80 
81  if(-1!=cb && ob<cb)
82  {
83  if(first)
84  first=false;
85  else
86  str << '\n';
87  str << (*it).mid(ob+1, (cb-ob)-1) << '|' << (*it).mid(0, ob);
88  }
89  }
90 
91  return filter;
92 }
93 #endif
94 
95 QString FileDialog::getExistingDirectory( QWidget * parent, const QString & caption, const QString & dirID ) {
96 #ifndef QT_NO_FILEDIALOG
97  const QString fname = QFileDialog::getExistingDirectory( parent, caption, dir( dirID ) );
98 #else
99  const QString fname = KFileDialog::getExistingDirectory( dir( dirID ), parent, caption );
100 #endif
101  update( fname, dirID );
102  return fname;
103 }
104 
105 QString FileDialog::getOpenFileName( QWidget * parent, const QString & caption, const QString & dirID, const QString & filter ) {
106 #ifndef QT_NO_FILEDIALOG
107  const QString fname = QFileDialog::getOpenFileName( parent, caption, dir( dirID ), filter );
108 #else
109  const QString fname = KFileDialog::getOpenFileName( dir( dirID ), qt2KdeFilter( filter ), parent, caption );
110 #endif
111  update( fname, dirID );
112  return fname;
113 }
114 
115 QStringList FileDialog::getOpenFileNames( QWidget * parent, const QString & caption, const QString & dirID, const QString & filter ) {
116 #ifndef QT_NO_FILEDIALOG
117  const QStringList files = QFileDialog::getOpenFileNames( parent, caption, dir( dirID ), filter );
118 #else
119  const QStringList files = KFileDialog::getOpenFileNames( dir( dirID ), qt2KdeFilter( filter ), parent, caption );
120 #endif
121  if ( !files.empty() )
122  update( files.front(), dirID );
123  return files;
124 }
125 
126 QString FileDialog::getSaveFileName( QWidget * parent, const QString & caption, const QString & dirID, const QString & filter ) {
127 #ifndef QT_NO_FILEDIALOG
128  const QString fname = QFileDialog::getSaveFileName( parent, caption, dir( dirID ), filter );
129 #else
130  const QString fname = KFileDialog::getSaveFileName( dirID.isEmpty() ? KUrl() : dir( dirID ), qt2KdeFilter( filter ), parent, caption );
131 #endif
132  update( fname, dirID );
133  return fname;
134 }
135 
136 QString FileDialog::getSaveFileNameEx( QWidget * parent, const QString & caption, const QString & dirID, const QString & proposedFileName, const QString & filter ) {
137  if ( proposedFileName.isEmpty() )
138 #ifndef QT_NO_FILEDIALOG
139  return getSaveFileName( parent, caption, dirID, filter );
140  const QString fname = QFileDialog::getSaveFileName( parent, caption, QDir( dir( dirID ) ).filePath( proposedFileName ), filter );
141 #else
142  return getSaveFileName( parent, caption, QString(), filter );
143  const QString fname = KFileDialog::getSaveFileName( QDir( dir( dirID ) ).filePath( proposedFileName ), qt2KdeFilter( filter ), parent, caption );
144 #endif
145  update( fname, dirID );
146  return fname;
147 }
Kleo::FileDialog::getOpenFileName
QString getOpenFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:105
QWidget
Kleo::FileDialog::getExistingDirectory
QString getExistingDirectory(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString())
Definition: filedialog.cpp:95
Kleo::FileDialog::getOpenFileNames
QStringList getOpenFileNames(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:115
Kleo::FileDialog::getSaveFileName
QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:126
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:136
dir
static QString dir(const QString &id)
Definition: filedialog.cpp:53
update
static void update(const QString &fname, const QString &id)
Definition: filedialog.cpp:61
QMap
Definition: signingcertificateselectiondialog.h:41
filedialog.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 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

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