30 #include <kblog/blogger1.h>
31 #include <kblog/metaweblog.h>
32 #include <kblog/movabletype.h>
33 #include <kblog/wordpressbuggy.h>
36 #include <kmessagebox.h>
38 #include <kio/jobclasses.h>
41 #include <QTableWidget>
45 class AddEditBlog::Private
53 mFetchProfileIdTimer(0),
58 Ui::AddEditBlogBase ui;
63 QTimer* mFetchProfileIdTimer;
71 :
KDialog( parent, flags ), d(new Private)
75 d->ui.setupUi( d->mainW );
76 setMainWidget( d->mainW );
79 d->mFetchAPITimer = d->mFetchBlogIdTimer = d->mFetchProfileIdTimer = 0;
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()) );
94 setWindowTitle( i18n(
"Edit blog settings" ) );
95 enableButtonOk(
true );
96 d->ui.btnFetch->setEnabled(
true );
97 d->ui.btnAutoConf->setEnabled(
true );
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();
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);
111 setWindowTitle( i18n(
"Add a new blog" ) );
113 d->bBlog->setBlogId(
QString() );
114 enableButtonOk(
false );
115 d->ui.txtTitle->setEnabled(
false);
119 d->ui.txtUrl->setFocus();
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 );
128 d->ui.btnAutoConf->setEnabled(
true );
129 d->ui.btnFetch->setEnabled(
true );
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" ) );
142 showWaitWidget( i18n(
"Trying to guess blog and API type...") );
145 if ( d->ui.txtUrl->text().contains(
QLatin1String(
"xmlrpc.php"), Qt::CaseInsensitive ) ) {
146 d->ui.comboApi->setCurrentIndex( 3 );
150 if ( d->ui.txtUrl->text().contains(
QLatin1String(
"blogspot"), Qt::CaseInsensitive ) ) {
151 d->ui.comboApi->setCurrentIndex( 4 );
155 if ( d->ui.txtUrl->text().contains(
QLatin1String(
"wordpress"), Qt::CaseInsensitive ) ) {
156 d->ui.comboApi->setCurrentIndex( 3 );
158 textUrl = d->ui.txtUrl->text();
162 d->ui.txtUrl->setText( textUrl +
QLatin1String(
"/xmlrpc.php") );
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() );
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 );
181 d->mFetchAPITimer->start(
TIMEOUT );
188 if ( job->error() ) {
189 kDebug() <<
"Auto configuration failed! Error: " << job->errorString();
191 KMessageBox::sorry(
this, i18n(
"Auto configuration failed. You have to set Blog API on Advanced tab manually."));
198 if ( rxGData.
indexIn( httpData ) != -1 ) {
199 kDebug() <<
"content='blogger' name='generator' matched";
200 d->mFetchAPITimer->deleteLater();
201 d->ui.comboApi->setCurrentIndex( 4 );
203 d->ui.txtId->setText( rxBlogId.
cap( 1 ) );
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() );
221 if ( rxWordpress.
indexIn( httpData ) != -1 ) {
222 kDebug() <<
"name=\"generator\" content=\"WordPress matched";
223 d->mFetchAPITimer->deleteLater();
224 d->ui.comboApi->setCurrentIndex( 3 );
226 textUrl = d->ui.txtUrl->text();
230 d->ui.txtUrl->setText( textUrl +
QLatin1String(
"/xmlrpc.php") );
236 textUrl = d->ui.txtUrl->text();
240 KIO::StoredTransferJob *testXmlRpcJob = KIO::storedGet(
QString::fromLatin1(
"%1/xmlrpc.php").arg(textUrl),
241 KIO::NoReload, KIO::HideProgressInfo );
243 connect( testXmlRpcJob, SIGNAL(result(KJob*)),
this, SLOT(
gotXmlRpcTest(KJob*)) );
249 d->mFetchAPITimer->deleteLater();
252 if ( job->error() ) {
253 kDebug() <<
"Auto configuration failed! Error: " << job->errorString();
255 KMessageBox::sorry(
this, i18n(
"Auto configuration failed. You have to set Blog API on Advanced tab manually."));
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();
266 d->ui.txtUrl->setText( textUrl +
QLatin1String(
"/xmlrpc.php") );
272 switch ( d->ui.comboApi->currentIndex() ) {
278 KBlog::Blogger1 *blog =
new KBlog::Blogger1( KUrl( d->ui.txtUrl->text() ),
this );
280 blog->setUsername( d->ui.txtUser->text() );
281 blog->setPassword( d->ui.txtPass->text() );
284 d->mFetchBlogIdTimer =
new QTimer(
this );
285 d->mFetchBlogIdTimer->setSingleShot(
true );
287 d->mFetchBlogIdTimer->start(
TIMEOUT );
295 blog->setUsername( d->ui.txtUser->text() );
296 blog->setPassword( d->ui.txtPass->text() );
297 blog->
setApiKey(
QLatin1String(
"500754804903-g6n1rfjjcmhct64p3qgj6ma3oo8l8s6a.apps.googleusercontent.com") );
305 kDebug()<<
"Unknown API";
309 connect( d->mBlog, SIGNAL(error(KBlog::Blog::ErrorType,
QString)),
311 d->ui.txtId->setText( i18n(
"Please wait..." ) );
312 d->ui.txtId->setEnabled(
false );
313 showWaitWidget( i18n(
"Fetching Blog Id..." ) );
319 if ( d->mFetchBlogIdTimer ) {
320 d->mFetchBlogIdTimer->stop();
322 if( d->mFetchProfileIdTimer ) {
323 d->mFetchProfileIdTimer->stop();
325 d->ui.txtId->setText(
QString() );
326 d->ui.txtId->setEnabled(
true );
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." ) );
336 d->mFetchAPITimer->deleteLater();
337 d->mFetchAPITimer = 0;
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" ) );
348 kDebug() <<
" ErrorType: " << type;
349 d->ui.txtId->setEnabled(
true );
350 d->ui.txtId->setText(
QString() );
352 KMessageBox::detailedError(
this, i18n(
"Fetching BlogID Failed.\nPlease check your Internet connection." ), errorMsg );
357 if( d->mFetchBlogIdTimer ) {
358 d->mFetchBlogIdTimer->deleteLater();
359 d->mFetchBlogIdTimer = 0;
362 QString blogId, blogName, blogUrl, apiUrl;
363 const int listCount(list.count());
364 if ( listCount > 1 ) {
365 kDebug() <<
"User has more than ONE blog!";
374 headers<<i18n(
"Title")<<i18n(
"Url");
379 for(;it != endIt; ++it){
388 blogsDialog->setMainWidget(blogsList);
389 blogsDialog->setWindowTitle( i18n(
"Which blog?") );
390 if( blogsDialog->exec() ) {
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();
405 }
else if (listCount > 0) {
411 KMessageBox::sorry(
this, i18n(
"Sorry, No blog found with the specified account info."));
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 );
421 d->ui.txtUrl->setText( apiUrl );
423 apiUrl = d->ui.txtUrl->text();
426 d->bBlog->setBlogUrl( blogUrl );
428 if(d->tmpBlogUrl.isEmpty())
429 d->bBlog->setBlogUrl( apiUrl );
431 d->bBlog->setBlogUrl( d->tmpBlogUrl );
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 );
443 const bool check = !txt.
isEmpty();
444 enableButtonOk( check );
445 d->ui.txtTitle->setEnabled( check );
451 if(isButtonEnabled(KDialog::Ok)){
452 setButtonFocus(KDialog::Ok);
454 if(d->mainW->currentIndex()==0){
455 if(d->ui.btnAutoConf->isEnabled()){
473 const QString yesText = i18nc(
"Supported feature or Not",
"Yes" );
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" );
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 );
485 d->ui.featureCreateCategory->setStyleSheet( noStyle );
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 );
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 );
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 );
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 );
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 );
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." )
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());
573 if ( d->isNewBlog ) {
575 d->bBlog->setId( blog_id );
576 if ( blog_id != -1 ) {
577 kDebug() <<
"Emitting sigBlogAdded() ...";
580 kDebug() <<
"Cannot add blog";
584 kDebug() <<
"Emitting sigBlogEdited() ...";
587 kDebug() <<
"Cannot edit blog with id " << d->bBlog->id();
592 KDialog::slotButtonClicked( button );
595 void AddEditBlog::showWaitWidget(
QString text )
597 d->ui.btnAutoConf->setEnabled(
false );
598 d->ui.btnFetch->setEnabled(
false );
601 d->wait->setWindowModality( Qt::WindowModal );
602 d->wait->setBusyState();
604 d->wait->setText( text );
608 void AddEditBlog::hideWaitWidget()
610 d->ui.btnAutoConf->setEnabled(
true );
611 d->ui.btnFetch->setEnabled(
true );
613 d->wait->deleteLater();
619 d->bBlog->setAuthData(authData);
623 d->mFetchBlogIdTimer =
new QTimer(
this );
624 d->mFetchBlogIdTimer->setSingleShot(
true );
626 d->mFetchBlogIdTimer->start(
TIMEOUT );
void slotComboApiChanged(int index)
const_iterator constBegin() const
void setApiKey(const QString &apiKey)
Sets Google OAuth application API key.
void bloggerAuthenticated(const QMap< QString, QString > &authData)
QString cap(int nth) const
void handleFetchError(KBlog::Blog::ErrorType type, const QString &errorMsg)
static DBMan * self()
Retrieve the instance of DataBase Manager.
QString & remove(int position, int n)
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
BilboBlog * blog(int blog_id)
QString as Title, and int as blog_id.
void handleFetchIDTimeout()
int indexIn(const QString &str, int offset, CaretMode caretMode) const
void setSupportedFeatures(BilboBlog::ApiType api)
QString fromUtf8(const char *str, int size)
This file is part of the for accessing Blog Servers from the Google's Blogger and BlogPost service an...
AddEditBlog(int blog_id, QWidget *parent=0, Qt::WindowFlags flags=0)
void gotXmlRpcTest(KJob *job)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
void setColumnHidden(int column, bool hide)
void sigBlogEdited(const BilboBlog &)
int addBlog(const BilboBlog &blog)
END.
QString & replace(int position, int n, QChar after)
void enableOkButton(const QString &)
void authenticate(const QMap< QString, QString > &authData=QMap< QString, QString >())
Authenticate this instance of Blogger against Google account.
A class that can be used for access to Google blogs.
void handleFetchAPITimeout()
QString fromLatin1(const char *str, int size)
void fetchedBlogId(const QList< QMap< QString, QString > > &list)
const_iterator constEnd() const
const_iterator constBegin() const
void setSecretKey(const QString &secretKey)
Sets Google OAuth application secret key.
void sigBlogAdded(const BilboBlog &)
virtual void slotButtonClicked(int button)
void listBlogs()
List the blogs available for this authentication on the server.