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

blogilo

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