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

mailcommon

  • sources
  • kde-4.14
  • kdepim
  • mailcommon
  • filter
  • dialog
selectthunderbirdfilterfileswidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "selectthunderbirdfilterfileswidget.h"
19 #include "ui_selectthunderbirdfilterfileswidget.h"
20 #include "mailimporter/filter_thunderbird.h"
21 #include <QAbstractButton>
22 #include <QListWidgetItem>
23 
24 SelectThunderbirdFilterFilesWidget::SelectThunderbirdFilterFilesWidget(const QString &defaultSettingPath, QWidget *parent) :
25  QWidget(parent),
26  ui(new Ui::SelectThunderbirdFilterFilesWidget)
27 {
28  ui->setupUi(this);
29  connect(ui->buttonGroup,SIGNAL(buttonClicked(QAbstractButton*)),SLOT(slotButtonClicked(QAbstractButton*)));
30  connect(ui->profiles,SIGNAL(currentIndexChanged(int)),SLOT(slotProfileChanged(int)));
31 
32  ui->listFiles->setSelectionMode(QAbstractItemView::MultiSelection);
33  QString defaultProfile;
34  QMap<QString,QString> listProfile = MailImporter::FilterThunderbird::listProfile(defaultProfile, defaultSettingPath);
35  QMap<QString, QString>::const_iterator i = listProfile.constBegin();
36  while (i != listProfile.constEnd()) {
37  QString name = i.key();
38  if (i.value()==defaultProfile){
39  name+=i18n(" (default)");
40  }
41  ui->profiles->addItem(name,i.value());
42  ++i;
43  }
44  ui->fileUrl->setEnabled(true);
45  ui->profiles->setEnabled(false);
46  ui->listFiles->setEnabled(false);
47  slotProfileChanged(0);
48  connect(ui->fileUrl, SIGNAL(textChanged(QString)), SLOT(slotUrlChanged(QString)));
49  connect(ui->listFiles, SIGNAL(itemSelectionChanged()), SLOT(slotItemSelectionChanged()));
50  Q_EMIT enableOkButton(false);
51 }
52 
53 SelectThunderbirdFilterFilesWidget::~SelectThunderbirdFilterFilesWidget()
54 {
55  delete ui;
56 }
57 
58 void SelectThunderbirdFilterFilesWidget::slotItemSelectionChanged()
59 {
60  Q_EMIT enableOkButton(!ui->listFiles->selectedItems().isEmpty());
61 }
62 
63 void SelectThunderbirdFilterFilesWidget::slotUrlChanged(const QString &path)
64 {
65  Q_EMIT enableOkButton(!path.isEmpty());
66 }
67 
68 void SelectThunderbirdFilterFilesWidget::slotButtonClicked(QAbstractButton*button)
69 {
70  if (button == ui->selectFile) {
71  ui->fileUrl->setEnabled(true);
72  ui->profiles->setEnabled(false);
73  ui->listFiles->setEnabled(false);
74  Q_EMIT enableOkButton(!ui->fileUrl->text().isEmpty());
75  } else {
76  ui->fileUrl->setEnabled(false);
77  ui->profiles->setEnabled(true);
78  ui->listFiles->setEnabled(true);
79  slotItemSelectionChanged();
80  }
81 }
82 
83 void SelectThunderbirdFilterFilesWidget::slotProfileChanged(int index)
84 {
85  if (index >= ui->profiles->count()) {
86  return;
87  }
88 
89  QStringList listFilterFiles;
90  const QString path(MailImporter::FilterThunderbird::defaultSettingsPath() + ui->profiles->itemData(index).toString());
91  QDir dir(path);
92  const QStringList subDir = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name);
93  Q_FOREACH( const QString& mailPath, subDir ) {
94  const QString subMailPath(path + QLatin1Char('/') + mailPath);
95  QDir dirMail(subMailPath);
96  const QStringList subDirMail = dirMail.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name);
97  Q_FOREACH( const QString& file, subDirMail ) {
98  const QString filterFile(subMailPath +QLatin1Char('/')+ file + QLatin1String("/msgFilterRules.dat"));
99  if (QFile(filterFile).exists()) {
100  listFilterFiles<<filterFile;
101  }
102  }
103  }
104  ui->listFiles->clear();
105  ui->listFiles->addItems(listFilterFiles);
106 }
107 
108 QStringList SelectThunderbirdFilterFilesWidget::selectedFiles() const
109 {
110  QStringList listFiles;
111  if (ui->selectFile->isChecked()) {
112  listFiles<<ui->fileUrl->url().path();
113  } else {
114  QList<QListWidgetItem *> list = ui->listFiles->selectedItems();
115  Q_FOREACH(QListWidgetItem * item, list) {
116  listFiles<<item->text();
117  }
118  }
119  return listFiles;
120 }
121 
122 void SelectThunderbirdFilterFilesWidget::setStartDir(const KUrl &url)
123 {
124  ui->fileUrl->setFilter(QLatin1String("*.dat"));
125  ui->fileUrl->setStartDir(url);
126 }
127 
QWidget
QMap::constBegin
const_iterator constBegin() const
QMap< QString, QString >
QListWidgetItem
SelectThunderbirdFilterFilesWidget::selectedFiles
QStringList selectedFiles() const
Definition: selectthunderbirdfilterfileswidget.cpp:108
QFile
SelectThunderbirdFilterFilesWidget::SelectThunderbirdFilterFilesWidget
SelectThunderbirdFilterFilesWidget(const QString &defaultSettingPath, QWidget *parent=0)
Definition: selectthunderbirdfilterfileswidget.cpp:24
QObject::name
const char * name() const
SelectThunderbirdFilterFilesWidget::enableOkButton
void enableOkButton(bool)
QString::isEmpty
bool isEmpty() const
QMap::constEnd
const_iterator constEnd() const
QString
QList
QStringList
QLatin1Char
SelectThunderbirdFilterFilesWidget::setStartDir
void setStartDir(const KUrl &)
Definition: selectthunderbirdfilterfileswidget.cpp:122
QMap::key
const Key key(const T &value) const
QDir
QAbstractButton
QLatin1String
selectthunderbirdfilterfileswidget.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
SelectThunderbirdFilterFilesWidget
Definition: selectthunderbirdfilterfileswidget.h:29
SelectThunderbirdFilterFilesWidget::~SelectThunderbirdFilterFilesWidget
~SelectThunderbirdFilterFilesWidget()
Definition: selectthunderbirdfilterfileswidget.cpp:53
QListWidgetItem::text
QString text() const
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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