20 #include "pimcommon/texteditor/plaintexteditor/plaintexteditorwidget.h"
21 #include "pimcommon/texteditor/plaintexteditor/plaintexteditor.h"
23 #include <KPIMUtils/ProgressIndicatorLabel>
27 #include <KTemporaryFile>
29 #include <QHBoxLayout>
32 using namespace MessageViewer;
37 setCaption( i18n(
"Show adblock list") );
40 QVBoxLayout *lay =
new QVBoxLayout;
41 mTextEdit =
new PimCommon::PlainTextEditorWidget;
43 mTextEdit->setReadOnly(
true);
44 lay->addWidget(mTextEdit);
46 mProgress =
new KPIMUtils::ProgressIndicatorLabel(i18n(
"Download..."));
47 lay->addWidget(mProgress);
55 delete mTemporaryFile;
59 void AdBlockShowListDialog::writeConfig()
61 KConfigGroup group( KGlobal::config(),
"AdBlockShowListDialog" );
62 group.writeEntry(
"Size", size() );
65 void AdBlockShowListDialog::readConfig()
67 KConfigGroup group( KGlobal::config(),
"AdBlockShowListDialog" );
68 const QSize sizeDialog = group.readEntry(
"Size", QSize(800,600) );
69 if ( sizeDialog.isValid() ) {
76 if (localPath.isEmpty()) {
77 QFile file(localPath);
79 mTextEdit->editor()->setPlainText(QString::fromUtf8(file.readAll()));
88 void AdBlockShowListDialog::downLoadList(
const QString &url)
90 delete mTemporaryFile;
91 mTemporaryFile =
new KTemporaryFile;
92 if (!mTemporaryFile->open()) {
93 kDebug()<<
"can not open temporary file";
94 delete mTemporaryFile;
100 KUrl destUrl = KUrl(mTemporaryFile->fileName());
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"));
110 connect(job, SIGNAL(finished(KJob*)),
this, SLOT(slotFinished(KJob*)));
113 void AdBlockShowListDialog::slotFinished(KJob *job)
117 mTemporaryFile->close();
118 delete mTemporaryFile;
120 mTextEdit->editor()->setPlainText(i18n(
"An error occurs during download list: \"%1\"", job->errorString()));
124 QFile f(mTemporaryFile->fileName());
125 if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
126 mTextEdit->editor()->setPlainText(QString::fromUtf8(f.readAll()));
128 mTemporaryFile->close();
129 delete mTemporaryFile;
134 #include "adblockshowlistdialog.moc"
void setAdBlockListPath(const QString &localPath, const QString &url)
AdBlockShowListDialog(QWidget *parent=0)