33 #include <config-kleopatra.h>
43 #include <QListWidget>
44 #include <QHBoxLayout>
45 #include <QPushButton>
46 #include <QStringList>
47 #include <QVBoxLayout>
52 using namespace Kleo::Crypto::Gui;
54 class ObjectsPage::Private {
55 friend class ::Kleo::Crypto::Gui::ObjectsPage;
61 void addFile(
const QFileInfo& i );
63 void listSelectionChanged();
65 AbsoluteFilePathRole=Qt::UserRole
69 QListWidget * fileListWidget;
70 QPushButton * removeButton;
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 );
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();
95 ObjectsPage::Private::~Private() {}
97 void ObjectsPage::Private::add()
100 if ( fname.isEmpty() )
102 addFile( QFileInfo( fname ) );
103 emit
q->completeChanged();
106 void ObjectsPage::Private::remove()
109 assert( !selected.isEmpty() );
110 Q_FOREACH ( QListWidgetItem *
const i, selected )
112 emit
q->completeChanged();
117 removeButton->setEnabled( !fileListWidget->selectedItems().isEmpty() );
121 :
WizardPage( parent, f ),
d( new Private( this ) )
131 d->fileListWidget->clear();
132 Q_FOREACH (
const QString& i, list )
133 d->addFile( QFileInfo( i ) );
138 void ObjectsPage::Private::addFile(
const QFileInfo& info )
140 QListWidgetItem*
const item =
new QListWidgetItem;
142 item->setIcon( KIcon( QLatin1String(
"folder") ) );
143 item->setText( info.fileName() );
144 item->setData( AbsoluteFilePathRole, info.absoluteFilePath() );
145 fileListWidget->addItem( item );
151 for (
int i = 0; i < d->fileListWidget->count(); ++i )
153 const QListWidgetItem*
const item = d->fileListWidget->item( i );
154 list.push_back( item->data( Private::AbsoluteFilePathRole ).toString() );
161 return d->fileListWidget->count() > 0;
164 #include "moc_objectspage.cpp"
QString getOpenFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
ObjectsPage(QWidget *parent=0, Qt::WindowFlags f=0)
void setFiles(const QStringList &files)
QStringList files() const