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

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • adblock
adblockshowlistdialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-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 "adblockshowlistdialog.h"
19 #include "adblocksyntaxhighlighter.h"
20 #include "pimcommon/texteditor/plaintexteditor/plaintexteditorwidget.h"
21 #include "pimcommon/texteditor/plaintexteditor/plaintexteditor.h"
22 
23 #include <KPIMUtils/ProgressIndicatorLabel>
24 
25 #include <KLocalizedString>
26 #include <KIO/Job>
27 #include <KTemporaryFile>
28 #include <KSharedConfig>
29 
30 #include <QHBoxLayout>
31 #include <KDebug>
32 
33 using namespace MessageViewer;
34 AdBlockShowListDialog::AdBlockShowListDialog(QWidget *parent)
35  : KDialog(parent),
36  mTemporaryFile(0)
37 {
38  setCaption( i18n("Show adblock list") );
39  setButtons( User1|Close );
40  setButtonText(User1, i18n("Delete list"));
41  enableButton(User1, false);
42  connect(this, SIGNAL(user1Clicked()), this, SLOT(slotDeleteBrokenList()));
43  QWidget *w = new QWidget;
44  QVBoxLayout *lay = new QVBoxLayout;
45  mTextEdit = new PimCommon::PlainTextEditorWidget;
46  (void)new MessageViewer::AdBlockSyntaxHighlighter(mTextEdit->editor()->document());
47  mTextEdit->setReadOnly(true);
48  lay->addWidget(mTextEdit);
49 
50  mProgress = new KPIMUtils::ProgressIndicatorLabel(i18n("Download..."));
51  lay->addWidget(mProgress);
52  w->setLayout(lay);
53  setMainWidget(w);
54  readConfig();
55 }
56 
57 AdBlockShowListDialog::~AdBlockShowListDialog()
58 {
59  delete mTemporaryFile;
60  writeConfig();
61 }
62 
63 void AdBlockShowListDialog::writeConfig()
64 {
65  KConfigGroup group( KGlobal::config(), "AdBlockShowListDialog" );
66  group.writeEntry( "Size", size() );
67 }
68 
69 void AdBlockShowListDialog::readConfig()
70 {
71  KConfigGroup group( KGlobal::config(), "AdBlockShowListDialog" );
72  const QSize sizeDialog = group.readEntry( "Size", QSize(800,600) );
73  if ( sizeDialog.isValid() ) {
74  resize( sizeDialog );
75  }
76 }
77 
78 void AdBlockShowListDialog::setAdBlockListPath(const QString &localPath, const QString &url)
79 {
80  if (localPath.isEmpty()) {
81  QFile file(localPath);
82  if (file.exists()) {
83  mTextEdit->editor()->setPlainText(QString::fromUtf8(file.readAll()));
84  } else {
85  downLoadList(url);
86  }
87  } else {
88  downLoadList(url);
89  }
90 }
91 
92 void AdBlockShowListDialog::downLoadList(const QString &url)
93 {
94  delete mTemporaryFile;
95  mTemporaryFile = new KTemporaryFile;
96  if (!mTemporaryFile->open()) {
97  kDebug()<<"can not open temporary file";
98  delete mTemporaryFile;
99  mTemporaryFile = 0;
100  return;
101  }
102  KUrl subUrl(url);
103 
104  KUrl destUrl = KUrl(mTemporaryFile->fileName());
105 
106  mProgress->start();
107  KIO::FileCopyJob* job = KIO::file_copy(subUrl , destUrl, -1, KIO::HideProgressInfo | KIO::Overwrite);
108  job->metaData().insert(QLatin1String("ssl_no_client_cert"), QLatin1String("TRUE"));
109  job->metaData().insert(QLatin1String("ssl_no_ui"), QLatin1String("TRUE"));
110  job->metaData().insert(QLatin1String("UseCache"), QLatin1String("false"));
111  job->metaData().insert(QLatin1String("cookies"), QLatin1String("none"));
112  job->metaData().insert(QLatin1String("no-auth"), QLatin1String("true"));
113 
114  connect(job, SIGNAL(finished(KJob*)), this, SLOT(slotFinished(KJob*)));
115 }
116 
117 void AdBlockShowListDialog::slotFinished(KJob *job)
118 {
119  mProgress->stop();
120  if (job->error()) {
121  mTextEdit->editor()->setPlainText(i18n("An error occurs during download list: \"%1\"", job->errorString()));
122  enableButton(User1, true);
123  } else {
124  QFile f(mTemporaryFile->fileName());
125  if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
126  mTextEdit->editor()->setPlainText(QString::fromUtf8(f.readAll()));
127  }
128  }
129  mTemporaryFile->close();
130  delete mTemporaryFile;
131  mTemporaryFile = 0;
132 }
133 
134 void AdBlockShowListDialog::slotDeleteBrokenList()
135 {
136  Q_EMIT deleteList(mListName);
137  accept();
138 }
139 
140 void AdBlockShowListDialog::setListName(const QString &listName)
141 {
142  mListName = listName;
143 }
QWidget
QSize::isValid
bool isValid() const
adblocksyntaxhighlighter.h
KDialog
QFile::exists
bool exists() const
QFile
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QWidget::setLayout
void setLayout(QLayout *layout)
MessageViewer::AdBlockShowListDialog::~AdBlockShowListDialog
~AdBlockShowListDialog()
Definition: adblockshowlistdialog.cpp:57
QString::isEmpty
bool isEmpty() const
MessageViewer::AdBlockShowListDialog::setAdBlockListPath
void setAdBlockListPath(const QString &localPath, const QString &url)
Definition: adblockshowlistdialog.cpp:78
QIODevice::readAll
QByteArray readAll()
MessageViewer::AdBlockShowListDialog::deleteList
void deleteList(const QString &name)
QVBoxLayout
QString
QSize
adblockshowlistdialog.h
QLatin1String
MessageViewer::AdBlockShowListDialog::setListName
void setListName(const QString &listName)
Definition: adblockshowlistdialog.cpp:140
MessageViewer::AdBlockSyntaxHighlighter
Definition: adblocksyntaxhighlighter.h:26
MessageViewer::AdBlockShowListDialog::AdBlockShowListDialog
AdBlockShowListDialog(QWidget *parent=0)
Definition: adblockshowlistdialog.cpp:34
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • 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