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

blogilo

  • sources
  • kde-4.12
  • kdepim
  • blogilo
  • src
addeditblog.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Blogilo, A KDE Blogging Client
3 
4  Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
5  Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License or (at your option) version 3 or any later version
11  accepted by the membership of KDE e.V. (or its successor approved
12  by the membership of KDE e.V.), which shall act as a proxy
13  defined in Section 14 of version 3 of the license.
14 
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, see http://www.gnu.org/licenses/
23 */
24 
25 #include "addeditblog.h"
26 #include "waitwidget.h"
27 #include "bilboblog.h"
28 #include "dbman.h"
29 
30 #include <kblog/gdata.h>
31 #include <kblog/blogger1.h>
32 #include <kblog/metaweblog.h>
33 #include <kblog/movabletype.h>
34 #include <kblog/wordpressbuggy.h>
35 #include <kurl.h>
36 #include <kmessagebox.h>
37 #include <kdebug.h>
38 #include <kio/jobclasses.h>
39 #include <kio/job.h>
40 
41 #include <QTableWidget>
42 #include <QTimer>
43 #include <QTextDocument>
44 static const int TIMEOUT = 45000;
45 
46 class AddEditBlog::Private
47 {
48 public:
49  Private()
50  : mainW(0),
51  isNewBlog(false),
52  bBlog(0),
53  mBlog(0),
54  mFetchProfileIdTimer(0),
55  mFetchBlogIdTimer(0),
56  mFetchAPITimer(0),
57  wait(0)
58  {}
59  Ui::AddEditBlogBase ui;
60  KTabWidget *mainW;
61  bool isNewBlog;
62  BilboBlog *bBlog;
63  KBlog::Blog *mBlog;
64  QTimer* mFetchProfileIdTimer;
65  QTimer* mFetchBlogIdTimer;
66  QTimer* mFetchAPITimer;
67  WaitWidget *wait;
68  QString tmpBlogUrl;
69 };
70 
71 AddEditBlog::AddEditBlog( int blog_id, QWidget *parent, Qt::WindowFlags flags )
72  : KDialog( parent, flags ), d(new Private)
73 {
74  kDebug();
75  d->mainW = new KTabWidget( this );
76  d->ui.setupUi( d->mainW );
77  setMainWidget( d->mainW );
78 
79  d->isNewBlog = true;
80  d->mFetchAPITimer = d->mFetchBlogIdTimer = d->mFetchProfileIdTimer = 0;
81 
82  connect( d->ui.txtId, SIGNAL(textChanged(QString)), this, SLOT(enableOkButton(QString)) );
83  connect( d->ui.txtUrl, SIGNAL(textChanged(QString)), this, SLOT(enableAutoConfBtn()) );
84  connect( d->ui.txtUser, SIGNAL(textChanged(QString)), this, SLOT(enableAutoConfBtn()) );
85  connect( d->ui.txtPass, SIGNAL(textChanged(QString)), this, SLOT(enableAutoConfBtn()) );
86  connect( d->ui.btnAutoConf, SIGNAL(clicked()), this, SLOT(autoConfigure()) );
87  connect( d->ui.btnFetch, SIGNAL(clicked()), this, SLOT(fetchBlogId()) );
88  connect( d->ui.comboApi, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComboApiChanged(int)) );
89  connect( d->ui.txtUrl, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()) );
90  connect( d->ui.txtUser, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()) );
91  connect( d->ui.txtPass, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()) );
92  connect( d->ui.txtId, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()) );
93 
94  if ( blog_id > -1 ) {
95  setWindowTitle( i18n( "Edit blog settings" ) );
96  enableButtonOk( true );
97  d->ui.btnFetch->setEnabled( true );
98  d->ui.btnAutoConf->setEnabled( true );
99  d->isNewBlog = false;
100  d->bBlog = DBMan::self()->blog( blog_id );
101  d->ui.txtUrl->setText( d->bBlog->url().url() );
102  d->ui.txtUser->setText( d->bBlog->username() );
103  d->ui.txtPass->setText( d->bBlog->password() );
104  d->ui.txtId->setText( d->bBlog->blogid() );
105  QString title = d->bBlog->title();
106  title = title.replace(QLatin1String("&amp;"), QLatin1String("&"));
107  d->ui.txtTitle->setText( title );
108  d->ui.comboApi->setCurrentIndex( d->bBlog->api() );
109  d->ui.comboDir->setCurrentIndex( d->bBlog->direction() );
110  d->ui.txtTitle->setEnabled(true);
111  } else {
112  setWindowTitle( i18n( "Add a new blog" ) );
113  d->bBlog = new BilboBlog( this );
114  d->bBlog->setBlogId( QString() );
115  enableButtonOk( false );
116  d->ui.txtTitle->setEnabled(false);
117  }
118 
119  slotComboApiChanged( d->ui.comboApi->currentIndex() );
120  d->ui.txtUrl->setFocus();
121 }
122 
123 void AddEditBlog::enableAutoConfBtn()
124 {
125  if ( d->ui.txtUrl->text().isEmpty() || d->ui.txtUser->text().isEmpty() || d->ui.txtPass->text().isEmpty() ) {
126  d->ui.btnAutoConf->setEnabled( false );
127  d->ui.btnFetch->setEnabled( false );
128  } else {
129  d->ui.btnAutoConf->setEnabled( true );
130  d->ui.btnFetch->setEnabled( true );
131  }
132 }
133 
134 void AddEditBlog::autoConfigure()
135 {
136  kDebug();
137  if ( d->ui.txtUrl->text().isEmpty() || d->ui.txtUser->text().isEmpty() || d->ui.txtPass->text().isEmpty() ) {
138  kDebug() << "Username, Password or Url doesn't set!";
139  KMessageBox::sorry( this, i18n( "You have to set the username, password and URL of your blog or website." ),
140  i18n( "Incomplete fields" ) );
141  return;
142  }
143  showWaitWidget( i18n("Trying to guess blog and API type...") );
144  QString textUrl;
146  if ( d->ui.txtUrl->text().contains( QLatin1String("xmlrpc.php"), Qt::CaseInsensitive ) ) {
147  d->ui.comboApi->setCurrentIndex( 3 );
148  fetchBlogId();
149  return;
150  }
151  if ( d->ui.txtUrl->text().contains( QLatin1String("blogspot"), Qt::CaseInsensitive ) ) {
152  d->ui.comboApi->setCurrentIndex( 4 );
153  fetchBlogId();
154  return;
155  }
156  if ( d->ui.txtUrl->text().contains( QLatin1String("wordpress"), Qt::CaseInsensitive ) ) {
157  d->ui.comboApi->setCurrentIndex( 3 );
158 
159  textUrl = d->ui.txtUrl->text();
160  while (textUrl.endsWith(QLatin1Char('/'))) {
161  textUrl.remove(textUrl.length()-1, 1);
162  }
163  d->ui.txtUrl->setText( textUrl + QLatin1String("/xmlrpc.php") );
164  fetchBlogId();
165  return;
166  }
167  if ( d->ui.txtUrl->text().contains( QLatin1String("livejournal"), Qt::CaseInsensitive ) ) {
168  d->ui.comboApi->setCurrentIndex( 0 );
169  d->tmpBlogUrl = d->ui.txtUrl->text();
170  d->ui.txtUrl->setText( QLatin1String("http://www.livejournal.com/interface/blogger/") );
171  d->ui.txtId->setText( d->ui.txtUser->text() );
172  d->ui.txtTitle->setText( d->ui.txtUser->text() );
173  hideWaitWidget();
174  return;
175  }
176  kDebug() << "Trying to guess API type by Homepage contents";
177  KIO::StoredTransferJob *httpGetJob = KIO::storedGet( d->ui.txtUrl->text() , KIO::NoReload, KIO::HideProgressInfo );
178  connect( httpGetJob, SIGNAL(result(KJob*)), this, SLOT(gotHtml(KJob*)) );
179  d->mFetchAPITimer = new QTimer( this );
180  d->mFetchAPITimer->setSingleShot( true );
181  connect( d->mFetchAPITimer, SIGNAL(timeout()), this, SLOT(handleFetchAPITimeout()) );
182  d->mFetchAPITimer->start( TIMEOUT );
183 }
184 
185 void AddEditBlog::gotHtml( KJob *job )
186 {
187  if ( !job )
188  return;
189  if ( job->error() ) {
190  kDebug() << "Auto configuration failed! Error: " << job->errorString();
191  hideWaitWidget();
192  KMessageBox::sorry(this, i18n("Auto configuration failed. You have to set Blog API on Advanced tab manually."));
193  return;
194  }
195  QString httpData( QString::fromUtf8(static_cast<KIO::StoredTransferJob*>( job )->data() ) );
196  job->deleteLater();
197 
198  QRegExp rxGData( QString::fromLatin1( "content='blogger' name='generator'" ) );
199  if ( rxGData.indexIn( httpData ) != -1 ) {
200  kDebug() << "content='blogger' name='generator' matched";
201  d->mFetchAPITimer->deleteLater();
202  d->ui.comboApi->setCurrentIndex( 4 );
203  QRegExp rxBlogId( QString::fromLatin1("BlogID=(\\d+)" ) );
204  d->ui.txtId->setText( rxBlogId.cap( 1 ) );
205  hideWaitWidget();
206  return;
207  }
208 
209  QRegExp rxLiveJournal( QString::fromLatin1( "rel=\"openid.server\" href=\"http://www.livejournal.com/openid/server.bml\"" ) );
210  if ( rxLiveJournal.indexIn( httpData ) != -1 ) {
211  kDebug() << " rel=\"openid.server\" href=\"http://www.livejournal.com/openid/server.bml\" matched";
212  d->mFetchAPITimer->deleteLater();
213  d->ui.comboApi->setCurrentIndex( 0 );
214  d->ui.txtUrl->setText( QLatin1String("http://www.liverjournal.com/interface/blogger/") );
215  d->ui.txtId->setText( d->ui.txtUser->text() );
216  hideWaitWidget();
217  return;
218  }
219 
220  QString textUrl;
221  QRegExp rxWordpress( QString::fromLatin1( "name=\"generator\" content=\"WordPress" ) );
222  if ( rxWordpress.indexIn( httpData ) != -1 ) {
223  kDebug() << "name=\"generator\" content=\"WordPress matched";
224  d->mFetchAPITimer->deleteLater();
225  d->ui.comboApi->setCurrentIndex( 3 );
226 
227  textUrl = d->ui.txtUrl->text();
228  while (textUrl.endsWith(QLatin1Char('/'))) {
229  textUrl.remove(textUrl.length()-1, 1);
230  }
231  d->ui.txtUrl->setText( textUrl + QLatin1String("/xmlrpc.php") );
232  fetchBlogId();
233  return;
234  }
235 
236  // add MT for WordpressBuggy -> URL/xmlrpc.php exists
237  textUrl = d->ui.txtUrl->text();
238  while (textUrl.endsWith(QLatin1Char('/'))) {
239  textUrl.remove(textUrl.length()-1, 1);
240  }
241  KIO::StoredTransferJob *testXmlRpcJob = KIO::storedGet( QString::fromLatin1("%1/xmlrpc.php").arg(textUrl),
242  KIO::NoReload, KIO::HideProgressInfo );
243 
244  connect( testXmlRpcJob, SIGNAL(result(KJob*)), this, SLOT(gotXmlRpcTest(KJob*)) );
245 }
246 
247 void AddEditBlog::gotXmlRpcTest( KJob *job )
248 {
249  kDebug();
250  d->mFetchAPITimer->deleteLater();
251  if ( !job )
252  return;
253  if ( job->error() ) {
254  kDebug() << "Auto configuration failed! Error: " << job->errorString();
255  hideWaitWidget();
256  KMessageBox::sorry(this, i18n("Auto configuration failed. You have to set Blog API on Advanced tab manually."));
257  return;
258  }
259  KMessageBox::information(this, i18n("The program could not guess the API of your blog, "
260  "but has found an XMLRPC interface and is trying to use it.\n"
261  "The MovableType API is assumed for now; choose another API if you know the server supports it."));
262  d->ui.comboApi->setCurrentIndex( 2 );
263  QString textUrl = d->ui.txtUrl->text();
264  while (textUrl.endsWith(QLatin1Char('/'))) {
265  textUrl.remove(textUrl.length()-1, 1);
266  }
267  d->ui.txtUrl->setText( textUrl + QLatin1String("/xmlrpc.php") );
268  fetchBlogId();
269 }
270 
271 void AddEditBlog::fetchBlogId()
272 {
273  switch ( d->ui.comboApi->currentIndex() ) {
274  case 0:
275  case 1:
276  case 2:
277  case 3:
278  {
279  KBlog::Blogger1 *blog = new KBlog::Blogger1( KUrl( d->ui.txtUrl->text() ), this );
280  d->mBlog = blog;
281  blog->setUsername( d->ui.txtUser->text() );
282  blog->setPassword( d->ui.txtPass->text() );
283  connect( blog , SIGNAL(listedBlogs(QList<QMap<QString,QString> >)),
284  this, SLOT(fetchedBlogId(QList<QMap<QString,QString> >)) );
285  d->mFetchBlogIdTimer = new QTimer( this );
286  d->mFetchBlogIdTimer->setSingleShot( true );
287  connect( d->mFetchBlogIdTimer, SIGNAL(timeout()), this, SLOT(handleFetchIDTimeout()) );
288  d->mFetchBlogIdTimer->start( TIMEOUT );
289  blog->listBlogs();
290  break;
291  }
292  case 4:
293  {
294  KBlog::GData* blog = new KBlog::GData( d->ui.txtUrl->text() , this );
295  d->mBlog = blog;
296  blog->setUsername( d->ui.txtUser->text() );
297  blog->setPassword( d->ui.txtPass->text() );
298  connect( blog, SIGNAL(fetchedProfileId(QString)),
299  this, SLOT(fetchedProfileId(QString)) );
300  blog->fetchProfileId();
301  d->mFetchProfileIdTimer = new QTimer( this );
302  d->mFetchProfileIdTimer->setSingleShot( true );
303  connect( d->mFetchProfileIdTimer, SIGNAL(timeout()), this, SLOT(handleFetchIDTimeout()) );
304  d->mFetchProfileIdTimer->start( TIMEOUT );
305  break;
306  }
307  default:
308  kDebug()<<"Unknown API";
309  return;
310  }
311 
312  connect( d->mBlog, SIGNAL(error(KBlog::Blog::ErrorType,QString)),
313  this, SLOT(handleFetchError(KBlog::Blog::ErrorType,QString)) );
314  d->ui.txtId->setText( i18n( "Please wait..." ) );
315  d->ui.txtId->setEnabled( false );
316  showWaitWidget( i18n( "Fetching Blog Id..." ) );
317 }
318 
319 void AddEditBlog::handleFetchIDTimeout()
320 {
321  kDebug();
322  if ( d->mFetchBlogIdTimer ) {
323  d->mFetchBlogIdTimer->stop();
324  }
325  if( d->mFetchProfileIdTimer ) {
326  d->mFetchProfileIdTimer->stop();
327  }
328  d->ui.txtId->setText( QString() );
329  d->ui.txtId->setEnabled( true );
330  hideWaitWidget();
331  KMessageBox::error( this, i18n( "Fetching the blog id timed out. Check your Internet connection,"
332  "and your homepage URL, username or password.\nNote that the URL has to contain \"http://\"\n"
333  "If you are using a self-hosted Wordpress blog, you have to enable Remote Publishing in its configuration." ) );
334 }
335 
336 void AddEditBlog::handleFetchAPITimeout()
337 {
338  kDebug();
339  d->mFetchAPITimer->deleteLater();
340  d->mFetchAPITimer = 0;
341  hideWaitWidget();
342  d->ui.txtId->setEnabled( true );
343  d->ui.txtId->setText( QString() );
344  KMessageBox::sorry( this, i18n( "The API guess function has failed, "
345  "please check your Internet connection. Otherwise, you have to set the API type manually on the Advanced tab." ),
346  i18n( "Auto Configuration Failed" ) );
347 }
348 
349 void AddEditBlog::handleFetchError( KBlog::Blog::ErrorType type, const QString & errorMsg )
350 {
351  kDebug() << " ErrorType: " << type;
352  d->ui.txtId->setEnabled( true );
353  d->ui.txtId->setText( QString() );
354  hideWaitWidget();
355  KMessageBox::detailedError( this, i18n( "Fetching BlogID Failed.\nPlease check your Internet connection." ), errorMsg );
356 }
357 
358 void AddEditBlog::fetchedBlogId( const QList< QMap < QString , QString > > & list )
359 {
360  if( d->mFetchBlogIdTimer ) {
361  d->mFetchBlogIdTimer->deleteLater();
362  d->mFetchBlogIdTimer = 0;
363  }
364  hideWaitWidget();
365  QString blogId, blogName, blogUrl, apiUrl;
366  const int listCount(list.count());
367  if ( listCount > 1 ) {
368  kDebug() << "User has more than ONE blog!";
369  KDialog *blogsDialog = new KDialog(this);
370  QTableWidget *blogsList = new QTableWidget(blogsDialog);
371  blogsList->setSelectionBehavior(QAbstractItemView::SelectRows);
372  QList< QMap<QString,QString> >::const_iterator it = list.constBegin();
373  QList< QMap<QString,QString> >::const_iterator endIt = list.constEnd();
374  int i=0;
375  blogsList->setColumnCount(4);
376  QStringList headers;
377  headers<<i18n("Title")<<i18n("Url");
378 
379  blogsList->setHorizontalHeaderLabels(headers);
380  blogsList->setColumnHidden(2, true);
381  blogsList->setColumnHidden(3, true);
382  for(;it != endIt; ++it){
383  kDebug()<<it->value(QLatin1String("title"));
384  blogsList->insertRow(i);
385  blogsList->setCellWidget(i, 0, new QLabel( it->value(QLatin1String("title"))) );
386  blogsList->setCellWidget(i, 1, new QLabel( it->value(QLatin1String("url"))) );
387  blogsList->setCellWidget(i, 2, new QLabel( it->value(QLatin1String("id"))) );
388  blogsList->setCellWidget(i, 3, new QLabel( it->value(QLatin1String("apiUrl"))) );
389  ++i;
390  }
391  blogsDialog->setMainWidget(blogsList);
392  blogsDialog->setWindowTitle( i18n("Which blog?") );
393  if( blogsDialog->exec() ) {
394  int row = blogsList->currentRow();
395  if( row == -1 ) {
396  delete blogsDialog;
397  return;
398  }
399  blogId = qobject_cast<QLabel*>( blogsList->cellWidget(row, 2) )->text();
400  blogName = qobject_cast<QLabel*>( blogsList->cellWidget(row, 0) )->text();
401  blogUrl = qobject_cast<QLabel*>( blogsList->cellWidget(row, 1) )->text();
402  apiUrl = qobject_cast<QLabel*>( blogsList->cellWidget(row, 3) )->text();
403  } else {
404  delete blogsDialog;
405  return;
406  }
407  delete blogsDialog;
408  } else if (listCount > 0) {
409  blogId = list.constBegin()->value(QLatin1String("id"));
410  blogName = list.constBegin()->value(QLatin1String("title"));
411  blogUrl = list.constBegin()->value(QLatin1String("url"));
412  apiUrl = list.constBegin()->value(QLatin1String("apiUrl"));
413  } else {
414  KMessageBox::sorry(this, i18n("Sorry, No blog found with the specified account info."));
415  return;
416  }
417  d->ui.txtId->setText( blogId );
418  d->ui.txtTitle->setText( blogName );
419  d->ui.txtId->setEnabled( true );
420  d->ui.btnFetch->setEnabled( true );
421  d->ui.btnAutoConf->setEnabled( true );
422 
423  if( !apiUrl.isEmpty() ){
424  d->ui.txtUrl->setText( apiUrl );
425  } else {
426  apiUrl = d->ui.txtUrl->text();
427  }
428  if( !blogUrl.isEmpty() ) {
429  d->bBlog->setBlogUrl( blogUrl );
430  } else {
431  if(d->tmpBlogUrl.isEmpty())
432  d->bBlog->setBlogUrl( apiUrl );
433  else
434  d->bBlog->setBlogUrl( d->tmpBlogUrl );
435  }
436 
437  d->bBlog->setUrl( QUrl( apiUrl ) );
438  d->bBlog->setUsername( d->ui.txtUser->text() );
439  d->bBlog->setPassword( d->ui.txtPass->text() );
440  d->bBlog->setBlogId( blogId );
441  d->bBlog->setTitle( blogName );
442 }
443 
444 void AddEditBlog::fetchedProfileId( const QString &id )
445 {
446  kDebug();
447  Q_UNUSED(id);
448  d->mFetchProfileIdTimer->deleteLater();
449  d->mFetchProfileIdTimer = 0;
450  KBlog::GData* blog = static_cast<KBlog::GData*>( d->mBlog );
451  connect( blog, SIGNAL(listedBlogs(QList<QMap<QString,QString> >)),
452  this, SLOT(fetchedBlogId(QList<QMap<QString,QString> >)) );
453  connect( blog, SIGNAL(error(KBlog::Blog::ErrorType,QString)),
454  this, SLOT(handleFetchError(KBlog::Blog::ErrorType,QString)) );
455  d->mFetchBlogIdTimer = new QTimer( this );
456  d->mFetchBlogIdTimer->setSingleShot( true );
457  connect( d->mFetchBlogIdTimer, SIGNAL(timeout()), this, SLOT(handleFetchIDTimeout()) );
458  d->mFetchBlogIdTimer->start( TIMEOUT );
459  blog->listBlogs();
460 }
461 
462 void AddEditBlog::enableOkButton( const QString & txt )
463 {
464  const bool check = !txt.isEmpty();
465  enableButtonOk( check );
466  d->ui.txtTitle->setEnabled( check );
467 }
468 
469 void AddEditBlog::slotReturnPressed()
470 {
472  if(isButtonEnabled(KDialog::Ok)){
473  setButtonFocus(KDialog::Ok);
474  } else {
475  if(d->mainW->currentIndex()==0){
476  if(d->ui.btnAutoConf->isEnabled()){
477  autoConfigure();
478  }
479  } else {
480  fetchBlogId();
481  }
482  }
483 }
484 
485 AddEditBlog::~AddEditBlog()
486 {
487  kDebug();
488  delete d;
489 }
490 
491 void AddEditBlog::setSupportedFeatures( BilboBlog::ApiType api )
492 {
493  const QString yesStyle = QLatin1String("QLabel{color: green;}");
494  const QString yesText = i18nc( "Supported feature or Not", "Yes" );
495  const QString noStyle = QLatin1String("QLabel{color: red;}");
496  const QString noText = i18nc( "Supported feature or Not", "No, API does not support it" );
497  const QString notYetText = i18nc( "Supported feature or Not", "No, Blogilo does not yet support it" );
498 
499  d->ui.featureCreatePost->setText( yesText );
500  d->ui.featureCreatePost->setStyleSheet( yesStyle );
501  d->ui.featureRemovePost->setText( yesText );
502  d->ui.featureRemovePost->setStyleSheet( yesStyle );
503  d->ui.featurRecentPosts->setText( yesText );
504  d->ui.featurRecentPosts->setStyleSheet( yesStyle );
505 
506  d->ui.featureCreateCategory->setStyleSheet( noStyle );
507 
508  switch( api ) {
509  case BilboBlog::BLOGGER1_API:
510  d->ui.featureUploadMedia->setText( noText );
511  d->ui.featureUploadMedia->setStyleSheet( noStyle );
512  d->ui.featureCategories->setText( noText );
513  d->ui.featureCategories->setStyleSheet( noStyle );
514  d->ui.featureMultipagedPosts->setText( noText );
515  d->ui.featureMultipagedPosts->setStyleSheet( noStyle );
516  d->ui.featureCreateCategory->setText( noText );
517  d->ui.featureTags->setText( noText );
518  d->ui.featureTags->setStyleSheet( noStyle );
519  break;
520  case BilboBlog::METAWEBLOG_API:
521  d->ui.featureUploadMedia->setText( yesText );
522  d->ui.featureUploadMedia->setStyleSheet( yesStyle );
523  d->ui.featureCategories->setText( noText );
524  d->ui.featureCategories->setStyleSheet( noStyle );
525  d->ui.featureMultipagedPosts->setText( noText );
526  d->ui.featureMultipagedPosts->setStyleSheet( noStyle );
527  d->ui.featureCreateCategory->setText( noText );
528  d->ui.featureTags->setText( noText );
529  d->ui.featureTags->setStyleSheet( noStyle );
530  break;
531  case BilboBlog::MOVABLETYPE_API:
532  d->ui.featureUploadMedia->setText( yesText );
533  d->ui.featureUploadMedia->setStyleSheet( yesStyle );
534  d->ui.featureCategories->setText( yesText );
535  d->ui.featureCategories->setStyleSheet( yesStyle );
536  d->ui.featureMultipagedPosts->setText( yesText );
537  d->ui.featureMultipagedPosts->setStyleSheet( yesStyle );
538  d->ui.featureCreateCategory->setText( noText );
539  d->ui.featureTags->setText( yesText );
540  d->ui.featureTags->setStyleSheet( yesStyle );
541  break;
542  case BilboBlog::WORDPRESSBUGGY_API:
543  d->ui.featureUploadMedia->setText( yesText );
544  d->ui.featureUploadMedia->setStyleSheet( yesStyle );
545  d->ui.featureCategories->setText( yesText );
546  d->ui.featureCategories->setStyleSheet( yesStyle );
547  d->ui.featureMultipagedPosts->setText( yesText );
548  d->ui.featureMultipagedPosts->setStyleSheet( yesStyle );
549  d->ui.featureCreateCategory->setText( notYetText );
550  d->ui.featureTags->setText( yesText );
551  d->ui.featureTags->setStyleSheet( yesStyle );
552  break;
553  case BilboBlog::GDATA_API:
554  d->ui.featureUploadMedia->setText( noText );
555  d->ui.featureUploadMedia->setStyleSheet( noStyle );
556  d->ui.featureCategories->setText( noText );
557  d->ui.featureCategories->setStyleSheet( noStyle );
558  d->ui.featureMultipagedPosts->setText( noText );
559  d->ui.featureMultipagedPosts->setStyleSheet( noStyle );
560  d->ui.featureCreateCategory->setText( noText );
561  d->ui.featureTags->setText( yesText );
562  d->ui.featureTags->setStyleSheet( yesStyle );
563  break;
564  };
565 }
566 
567 void AddEditBlog::slotComboApiChanged( int index )
568 {
570  setSupportedFeatures( (BilboBlog::ApiType) index );
571 }
572 
573 void AddEditBlog::slotButtonClicked( int button )
574 {
575  kDebug();
576  if ( button == KDialog::Ok ) {
577  if ( d->bBlog->blogid().isEmpty() && d->ui.txtId->text().isEmpty() ) {
578  KMessageBox::sorry( this, i18n( "Blog ID has not yet been retrieved.\n"
579  "You can fetch the blog ID by clicking on \"Auto Configure\" or the \"Fetch ID\" button; otherwise, you have "
580  "to insert your blog ID manually." )
581  );
582  return;
583  }
584  d->bBlog->setApi(( BilboBlog::ApiType )d->ui.comboApi->currentIndex() );
585  d->bBlog->setDirection(( Qt::LayoutDirection )d->ui.comboDir->currentIndex() );
586  d->bBlog->setTitle( d->ui.txtTitle->text() );
587  d->bBlog->setPassword( d->ui.txtPass->text() );
588  d->bBlog->setUsername( d->ui.txtUser->text() );
589  d->bBlog->setBlogId( d->ui.txtId->text() );
590  d->bBlog->setUrl( KUrl( d->ui.txtUrl->text() ) );
591  if(d->bBlog->blogUrl().isEmpty())
592  d->bBlog->setBlogUrl(d->ui.txtUrl->text());
593 
594  if ( d->isNewBlog ) {
595  int blog_id = DBMan::self()->addBlog( *d->bBlog );
596  d->bBlog->setId( blog_id );
597  if ( blog_id != -1 ) {
598  kDebug() << "Emitting sigBlogAdded() ...";
599  Q_EMIT sigBlogAdded( *d->bBlog );
600  } else {
601  kDebug() << "Cannot add blog";
602  }
603  } else {
604  if ( DBMan::self()->editBlog( *d->bBlog ) ) {
605  kDebug() << "Emitting sigBlogEdited() ...";
606  Q_EMIT sigBlogEdited( *d->bBlog );
607  } else {
608  kDebug() << "Cannot edit blog with id " << d->bBlog->id();
609  }
610  }
611  accept();
612  } else
613  KDialog::slotButtonClicked( button );
614 }
615 
616 void AddEditBlog::showWaitWidget( QString text )
617 {
618  d->ui.btnAutoConf->setEnabled( false );
619  d->ui.btnFetch->setEnabled( false );
620  if( !d->wait ) {
621  d->wait = new WaitWidget(this);
622  d->wait->setWindowModality( Qt::WindowModal );
623  d->wait->setBusyState();
624  }
625  d->wait->setText( text );
626  d->wait->show();
627 }
628 
629 void AddEditBlog::hideWaitWidget()
630 {
631  d->ui.btnAutoConf->setEnabled( true );
632  d->ui.btnFetch->setEnabled( true );
633  if( d->wait )
634  d->wait->deleteLater();
635  d->wait = 0;
636 }
637 
638 #include "addeditblog.moc"
AddEditBlog::slotComboApiChanged
void slotComboApiChanged(int index)
Definition: addeditblog.cpp:567
AddEditBlog::fetchedProfileId
void fetchedProfileId(const QString &)
Definition: addeditblog.cpp:444
BilboBlog::METAWEBLOG_API
Definition: bilboblog.h:45
AddEditBlog::gotHtml
void gotHtml(KJob *)
Definition: addeditblog.cpp:185
AddEditBlog::enableAutoConfBtn
void enableAutoConfBtn()
Definition: addeditblog.cpp:123
AddEditBlog::handleFetchError
void handleFetchError(KBlog::Blog::ErrorType type, const QString &errorMsg)
Definition: addeditblog.cpp:349
QWidget
DBMan::self
static DBMan * self()
Retrieve the instance of DataBase Manager.
Definition: dbman.cpp:107
KDialog
DBMan::blog
BilboBlog * blog(int blog_id)
QString as Title, and int as blog_id.
Definition: dbman.cpp:851
BilboBlog::WORDPRESSBUGGY_API
Definition: bilboblog.h:45
AddEditBlog::handleFetchIDTimeout
void handleFetchIDTimeout()
Definition: addeditblog.cpp:319
AddEditBlog::fetchBlogId
void fetchBlogId()
Definition: addeditblog.cpp:271
AddEditBlog::~AddEditBlog
~AddEditBlog()
Definition: addeditblog.cpp:485
AddEditBlog::setSupportedFeatures
void setSupportedFeatures(BilboBlog::ApiType api)
Definition: addeditblog.cpp:491
BilboBlog
Blog definition class!
Definition: bilboblog.h:40
WaitWidget
This class is the widget for the WaitDialog including a progress bar.
Definition: waitwidget.h:36
waitwidget.h
AddEditBlog::AddEditBlog
AddEditBlog(int blog_id, QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: addeditblog.cpp:71
TIMEOUT
static const int TIMEOUT
Definition: addeditblog.cpp:44
addeditblog.h
AddEditBlog::gotXmlRpcTest
void gotXmlRpcTest(KJob *job)
Definition: addeditblog.cpp:247
BilboBlog::GDATA_API
Definition: bilboblog.h:45
AddEditBlog::sigBlogEdited
void sigBlogEdited(const BilboBlog &)
bilboblog.h
DBMan::addBlog
int addBlog(const BilboBlog &blog)
END.
Definition: dbman.cpp:274
dbman.h
AddEditBlog::enableOkButton
void enableOkButton(const QString &)
Definition: addeditblog.cpp:462
AddEditBlog::slotReturnPressed
void slotReturnPressed()
Definition: addeditblog.cpp:469
AddEditBlog::handleFetchAPITimeout
void handleFetchAPITimeout()
Definition: addeditblog.cpp:336
AddEditBlog::fetchedBlogId
void fetchedBlogId(const QList< QMap< QString, QString > > &list)
Definition: addeditblog.cpp:358
BilboBlog::BLOGGER1_API
Definition: bilboblog.h:45
BilboBlog::ApiType
ApiType
Definition: bilboblog.h:44
AddEditBlog::sigBlogAdded
void sigBlogAdded(const BilboBlog &)
BilboBlog::MOVABLETYPE_API
Definition: bilboblog.h:45
AddEditBlog::slotButtonClicked
virtual void slotButtonClicked(int button)
Definition: addeditblog.cpp:573
AddEditBlog::autoConfigure
void autoConfigure()
Definition: addeditblog.cpp:134
KTabWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:44 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

blogilo

Skip menu "blogilo"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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