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

messageviewer

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

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