• 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
  • crypto
  • gui
objectspage.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/gui/objectspage.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 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 #include <config-kleopatra.h>
34 
35 #include "objectspage.h"
36 
37 #include <utils/filedialog.h>
38 
39 #include <KIcon>
40 #include <KLocale>
41 
42 #include <QFileInfo>
43 #include <QListWidget>
44 #include <QHBoxLayout>
45 #include <QPushButton>
46 #include <QStringList>
47 #include <QVBoxLayout>
48 
49 #include <cassert>
50 
51 using namespace Kleo;
52 using namespace Kleo::Crypto::Gui;
53 
54 class ObjectsPage::Private {
55  friend class ::Kleo::Crypto::Gui::ObjectsPage;
56  ObjectsPage * const q;
57 public:
58  explicit Private( ObjectsPage * qq );
59  ~Private();
60  void add();
61  void addFile( const QFileInfo& i );
62  void remove();
63  void listSelectionChanged();
64  enum Role {
65  AbsoluteFilePathRole=Qt::UserRole
66  };
67 
68 private:
69  QListWidget * fileListWidget;
70  QPushButton * removeButton;
71 };
72 
73 
74 ObjectsPage::Private::Private( ObjectsPage * qq )
75  : q( qq )
76 {
77  q->setTitle( i18n( "<b>Objects</b>" ) );
78  QVBoxLayout* const top = new QVBoxLayout( q );
79  fileListWidget = new QListWidget;
80  fileListWidget->setSelectionMode( QAbstractItemView::MultiSelection );
81  connect( fileListWidget, SIGNAL(itemSelectionChanged()),
82  q, SLOT(listSelectionChanged()) );
83  top->addWidget( fileListWidget );
84  QWidget* const buttonWidget = new QWidget;
85  QHBoxLayout* const buttonLayout = new QHBoxLayout( buttonWidget );
86  removeButton = new QPushButton;
87  removeButton->setText( i18n( "Remove Selected" ) );
88  connect( removeButton, SIGNAL(clicked()), q, SLOT(remove()) );
89  buttonLayout->addWidget( removeButton );
90  buttonLayout->addStretch();
91  top->addWidget( buttonWidget );
92  listSelectionChanged();
93 }
94 
95 ObjectsPage::Private::~Private() {}
96 
97 void ObjectsPage::Private::add()
98 {
99  const QString fname = FileDialog::getOpenFileName( q, i18n( "Select File" ), QLatin1String("enc") );
100  if ( fname.isEmpty() )
101  return;
102  addFile( QFileInfo( fname ) );
103  emit q->completeChanged();
104 }
105 
106 void ObjectsPage::Private::remove()
107 {
108  const QList<QListWidgetItem*> selected = fileListWidget->selectedItems();
109  assert( !selected.isEmpty() );
110  Q_FOREACH ( QListWidgetItem * const i, selected )
111  delete i;
112  emit q->completeChanged();
113 }
114 
115 void ObjectsPage::Private::listSelectionChanged()
116 {
117  removeButton->setEnabled( !fileListWidget->selectedItems().isEmpty() );
118 }
119 
120 ObjectsPage::ObjectsPage( QWidget * parent, Qt::WindowFlags f )
121  : WizardPage( parent, f ), d( new Private( this ) )
122 {
123 
124 }
125 
126 
127 ObjectsPage::~ObjectsPage() {}
128 
129 void ObjectsPage::setFiles( const QStringList& list )
130 {
131  d->fileListWidget->clear();
132  Q_FOREACH ( const QString& i, list )
133  d->addFile( QFileInfo( i ) );
134  emit completeChanged();
135 }
136 
137 
138 void ObjectsPage::Private::addFile( const QFileInfo& info )
139 {
140  QListWidgetItem* const item = new QListWidgetItem;
141  if ( info.isDir() )
142  item->setIcon( KIcon( QLatin1String("folder") ) );
143  item->setText( info.fileName() );
144  item->setData( AbsoluteFilePathRole, info.absoluteFilePath() );
145  fileListWidget->addItem( item );
146 }
147 
148 QStringList ObjectsPage::files() const
149 {
150  QStringList list;
151  for ( int i = 0; i < d->fileListWidget->count(); ++i )
152  {
153  const QListWidgetItem* const item = d->fileListWidget->item( i );
154  list.push_back( item->data( Private::AbsoluteFilePathRole ).toString() );
155  }
156  return list;
157 }
158 
159 bool ObjectsPage::isComplete() const
160 {
161  return d->fileListWidget->count() > 0;
162 }
163 
164 #include "moc_objectspage.cpp"
165 
objectspage.h
Kleo::FileDialog::getOpenFileName
QString getOpenFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:105
Kleo::Crypto::Gui::ObjectsPage::~ObjectsPage
~ObjectsPage()
Definition: objectspage.cpp:127
QWidget
Kleo::Crypto::Gui::WizardPage::completeChanged
void completeChanged()
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Crypto::Gui::ObjectsPage::ObjectsPage
ObjectsPage(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: objectspage.cpp:120
Kleo::Crypto::Gui::ObjectsPage::setFiles
void setFiles(const QStringList &files)
Definition: objectspage.cpp:129
Kleo::Crypto::Gui::ObjectsPage::files
QStringList files() const
Definition: objectspage.cpp:148
Kleo::Crypto::Gui::ObjectsPage::isComplete
bool isComplete() const
Definition: objectspage.cpp:159
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::Crypto::Gui::ObjectsPage
Definition: objectspage.h:46
Kleo::Crypto::Gui::WizardPage
Definition: wizardpage.h:48
QList
Definition: commands/command.h:46
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