31 #include <KDE/KLocale>
32 #include <kdatetime.h>
35 #include <kio/deletejob.h>
36 #include <kmessagebox.h>
41 #include <QSqlDatabase>
51 KWallet::Wallet* mWallet;
52 QString mLastErrorText;
54 QMap<int, BilboBlog*> mBlogList;
61 d->mWallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 );
64 if ( !d->mWallet->hasFolder( QLatin1String(
"blogilo") ) ) {
65 d->mWallet->createFolder( QLatin1String(
"blogilo") );
67 d->mWallet->setFolder( QLatin1String(
"blogilo") );
68 kDebug() <<
"Wallet successfully opened.";
71 kDebug() <<
"Could not use Wallet service, will use database to store passwords";
74 if ( !QFile::exists(
CONF_DB ) ) {
75 if ( !this->createDB() ) {
76 KMessageBox::detailedError( 0, i18n(
"Cannot create database" ),
77 i18n( d->db.lastError().text().toUtf8().data() ) );
78 kDebug() <<
"Cannot create database, SQL error: " << d->db.lastError().text() << endl;
81 }
else if ( !connectDB() )
92 d->mWallet->deleteLater();
102 return d->mLastErrorText;
105 DBMan * DBMan::mSelf = 0L;
119 void DBMan::reloadBlogList()
121 d->mBlogList.clear();
122 QList<BilboBlog*> listBlogs = this->listBlogs();
123 const int count = listBlogs.count();
124 for (
int i = 0; i < count; ++i ) {
125 d->mBlogList [ listBlogs.at(i)->id() ] = listBlogs.at(i);
129 bool DBMan::connectDB()
134 d->db = QSqlDatabase::addDatabase( QLatin1String(
"QSQLITE") );
135 d->db.setDatabaseName( QString(
CONF_DB) );
137 if ( !d->db.open() ) {
138 KMessageBox::detailedError( 0, i18n(
"Cannot connect to database" ),
139 i18n( d->db.lastError().text().toUtf8().data() ) );
140 kDebug() <<
"Cannot connect to database, SQL error: " << d->db.lastError().text();
153 bool DBMan::createDB()
162 if ( !q.exec( QLatin1String(
"CREATE TABLE blog (id INTEGER PRIMARY KEY, blogid TEXT, blog_url TEXT, username TEXT,\
163 password TEXT, style_url TEXT, api_type TEXT, title TEXT, direction TEXT,\
164 local_directory TEXT, icon_url TEXT)") ) ) {
166 d->mLastErrorText = q.lastError().text();
170 if ( !q.exec( QLatin1String(
"CREATE TABLE post (id INTEGER PRIMARY KEY, postid TEXT NOT NULL, blog_id NUMERIC NOT NULL,\
171 author TEXT, slug TEXT, post_password TEXT, title TEXT, content TEXT, text_more TEXT,\
172 c_time TEXT, m_time TEXT, is_private NUMERIC, is_comment_allowed NUMERIC,\
173 is_trackback_allowed NUMERIC, link TEXT, perma_link TEXT, summary TEXT, tags TEXT,\
174 status NUMERIC, trackback_urls TEXT, UNIQUE(postid, blog_id));") ) ) {
176 d->mLastErrorText = q.lastError().text();
180 if ( !q.exec( QLatin1String(
"CREATE TABLE comment (id INTEGER PRIMARY KEY, commentid TEXT NOT NULL, blog_id NUMERIC NOT NULL,\
181 postId TEXT, author_name TEXT, author_url TEXT, author_email TEXT, title TEXT, content TEXT,\
182 c_time TEXT, m_time TEXT, link TEXT, password TEXT,\
183 status NUMERIC, UNIQUE(commentid, blog_id));" ) ) ){
185 d->mLastErrorText = q.lastError().text();
189 if ( !q.exec( QLatin1String(
"CREATE TABLE category (catid INTEGER PRIMARY KEY, name TEXT NOT NULL,\
190 description TEXT, htmlUrl TEXT, rssUrl TEXT, categoryId TEXT, parentId TEXT,\
191 blog_id NUMERIC NOT NULL, UNIQUE(name,blog_id));" ) ) ) {
193 d->mLastErrorText = q.lastError().text();
197 if( !q.exec( QLatin1String(
"CREATE TABLE file (fileid INTEGER PRIMARY KEY, name TEXT, blog_id NUMERIC, is_uploaded NUMERIC,\
198 local_url TEXT, remote_url TEXT, mime_type TEXT);" ) ) ) {
200 d->mLastErrorText = q.lastError().text();
204 if ( !q.exec( QLatin1String(
"CREATE TABLE post_cat (blogId TEXT NOT NULL, postId TEXT NOT NULL,\
205 categoryId TEXT NOT NULL, UNIQUE(blogId,postId,categoryId));" ) ) ) {
207 d->mLastErrorText = q.lastError().text();
211 if ( !q.exec( QLatin1String(
"CREATE TABLE post_file (post_id INTEGER, file_id INTEGER);" ) ) ) {
213 d->mLastErrorText = q.lastError().text();
217 if( !q.exec( QLatin1String(
"CREATE TABLE local_post (local_id INTEGER PRIMARY KEY, id INTEGER UNIQUE, postid TEXT, blog_id NUMERIC,\
218 author TEXT, slug TEXT, post_password TEXT, title TEXT, content TEXT, text_more TEXT,\
219 c_time TEXT, m_time TEXT, is_private NUMERIC, is_comment_allowed NUMERIC,\
220 is_trackback_allowed NUMERIC, link TEXT, perma_link TEXT, summary TEXT, tags TEXT,\
221 status NUMERIC);" ) ) ) {
223 d->mLastErrorText = q.lastError().text();
227 if( !q.exec( QLatin1String(
"CREATE TABLE local_post_cat (local_id INT, categoryId TEXT);" ) ) ) {
229 d->mLastErrorText = q.lastError().text();
233 if( !q.exec( QLatin1String(
"CREATE TABLE temp_post (local_id INTEGER PRIMARY KEY, id INTEGER UNIQUE, postid TEXT, blog_id NUMERIC,\
234 author TEXT, slug TEXT, post_password TEXT, title TEXT, content TEXT, text_more TEXT,\
235 c_time TEXT, m_time TEXT, is_private NUMERIC, is_comment_allowed NUMERIC,\
236 is_trackback_allowed NUMERIC, link TEXT, perma_link TEXT, summary TEXT, tags TEXT,\
237 status NUMERIC);" ) ) ){
239 d->mLastErrorText = q.lastError().text();
243 if( !q.exec( QLatin1String(
"CREATE TABLE temp_post_cat (local_id INT, categoryId TEXT);" ) ) ) {
245 d->mLastErrorText = q.lastError().text();
249 q.exec( QLatin1String(
"CREATE TRIGGER delete_post AFTER DELETE ON post\
251 DELETE FROM post_cat WHERE post_cat.postId=OLD.postid;\
252 DELETE FROM post_file WHERE post_file.post_id=OLD.id;\
253 DELETE FROM comment WHERE comment.postId=OLD.postid;\
255 q.exec( QLatin1String(
"CREATE TRIGGER delete_blog AFTER DELETE ON blog \
257 DELETE FROM category WHERE category.blog_id=OLD.id;\
258 DELETE FROM file WHERE file.blog_id=OLD.id;\
259 DELETE FROM post WHERE post.blog_id=OLD.id;\
260 DELETE FROM comment WHERE comment.blog_id=OLD.id;\
262 q.exec( QLatin1String(
"CREATE TRIGGER delete_temp_post AFTER DELETE ON temp_post \
264 DELETE FROM temp_post_cat WHERE local_id=OLD.local_id;\
266 q.exec( QLatin1String(
"CREATE TRIGGER delete_local_post AFTER DELETE ON local_post \
268 DELETE FROM local_post_cat WHERE local_id=OLD.local_id;\
278 q.prepare( QLatin1String(
"INSERT INTO blog (blogid, blog_url, username, style_url, api_type, title,\
279 direction, local_directory) VALUES(?, ?, ?, ?, ?, ?, ?, ?)" ) );
280 if ( d->mWallet && d->mWallet->writePassword( blog.
url().url() + QLatin1Char(
'_') + blog.
username(), blog.
password() ) == 0 )
281 kDebug() <<
"Password stored to kde wallet";
285 q.prepare( QLatin1String(
"INSERT INTO blog (password, blogid, blog_url, username, style_url, api_type, title,\
286 direction, local_directory) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)" ) );
289 q.addBindValue( blog.
blogid() );
290 q.addBindValue( blog.
url().url() );
292 q.addBindValue( blog.
blogUrl() );
293 q.addBindValue( blog.
api() );
294 q.addBindValue( blog.
title() );
300 return q.lastInsertId().toInt();
302 d->mLastErrorText = q.lastError().text();
311 q.prepare( QLatin1String(
"UPDATE blog SET blogid=?, blog_url=?, username=? , style_url=? , api_type=?, \
312 title=?, direction=?, local_directory=? WHERE id=?" ) );
313 if ( d->mWallet && d->mWallet->writePassword( blog.
url().url() + QLatin1Char(
'_') + blog.
username(), blog.
password() ) == 0 )
314 kDebug() <<
"Password stored to kde wallet";
318 q.prepare( QLatin1String(
"UPDATE blog SET password=?, blogid=?, blog_url=?, username=? , style_url=? , api_type=?, \
319 title=?, direction=?, local_directory=? WHERE id=?" ));
322 q.addBindValue( blog.
blogid() );
323 q.addBindValue( blog.
url().url() );
325 q.addBindValue( blog.
blogUrl() );
326 q.addBindValue( blog.
api() );
327 q.addBindValue( blog.
title() );
330 q.addBindValue( blog.
id() );
334 d->mLastErrorText = q.lastError().text();
335 kDebug() << q.lastError().text();
344 BilboBlog *tmp = d->mBlogList[ blog_id ];
346 if ( d->mWallet && d->mWallet->removeEntry( tmp->
url().url() + QLatin1Char(
'_') + tmp->
username() ) == 0 )
347 kDebug() <<
"Password removed to kde wallet";
350 q.prepare( QLatin1String(
"DELETE FROM blog WHERE id=?" ));
351 q.addBindValue( blog_id );
354 d->mLastErrorText = q.lastError().text();
355 kDebug() << q.lastError().text();
358 QString path = KStandardDirs::locateLocal(
"data", QString::fromLatin1(
"blogilo/%1/" ).arg( blog_id ) ,
false );
359 KIO::del(KUrl(path), KIO::HideProgressInfo);
366 kDebug() <<
"Adding post with title: " << post.title() <<
" to Blog " << blog_id;
368 q.prepare( QLatin1String(
"INSERT OR REPLACE INTO post (postid, blog_id, author, title, content, text_more, c_time, m_time,\
369 is_private, is_comment_allowed, is_trackback_allowed, link, perma_link, summary, slug,\
370 tags, status) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ) );
371 q.addBindValue( post.postId() );
372 q.addBindValue( blog_id );
373 q.addBindValue( post.
author() );
374 q.addBindValue( post.title() );
375 q.addBindValue( post.content() );
376 q.addBindValue( post.additionalContent() );
377 q.addBindValue( post.creationDateTime().
toString( KDateTime::ISODate ) );
378 q.addBindValue( ( post.modificationDateTime().isNull() ? post.creationDateTime().
toString( KDateTime::ISODate ) :
379 post.modificationDateTime().
toString( KDateTime::ISODate )) );
380 q.addBindValue( post.isPrivate() );
381 q.addBindValue( post.isCommentAllowed() );
382 q.addBindValue( post.isTrackBackAllowed() );
383 q.addBindValue( post.link().url() );
384 q.addBindValue( post.permaLink().url() );
385 q.addBindValue( post.summary() );
386 q.addBindValue( post.slug() );
387 q.addBindValue( post.tags().join(QLatin1String(
",")) );
388 q.addBindValue( post.status() );
392 ret = q.lastInsertId().toInt();
396 qd.prepare( QLatin1String(
"DELETE FROM post_cat WHERE postId=? AND blogId=(SELECT blogid FROM blog where id=?)" ));
397 qd.addBindValue(post.postId());
398 qd.addBindValue(blog_id);
400 d->mLastErrorText = qd.lastError().text();
401 kError() <<
"Cannot delete previous categories.";
404 int cat_count = post.categories().count();
405 if( cat_count > 0 ) {
408 q2.prepare( QLatin1String(
"INSERT OR REPLACE INTO post_cat (blogId, postId, categoryId)\
409 VALUES((SELECT blogid FROM blog where id=?), ?, \
410 (SELECT categoryId FROM category WHERE name = ? AND blog_id= ?))" ) );
411 for (
int i = 0; i < cat_count; ++i ) {
412 q2.addBindValue(blog_id);
413 q2.addBindValue(post.postId());
414 q2.addBindValue(post.categories()[i]);
415 q2.addBindValue(blog_id);
417 kDebug() <<
"Cannot add one of categories to Post, SQL Error: " << q2.lastError().text();
418 d->mLastErrorText = q.lastError().text();
423 d->mLastErrorText = q.lastError().text();
424 kDebug() <<
"Cannot Add post to database!\n\tSQL Error: " << q.lastError().text();
435 q.prepare( QLatin1String(
"UPDATE post SET author=?, title=?, content=?, text_more=?, c_time=?, m_time=?,\
436 is_private=?, is_comment_allowed=?, is_trackback_allowed=?, link=?, perma_link=?, summary=?,\
437 slug=?, tags=?, status=? WHERE postid=? AND blog_id=?" ) );
438 q.addBindValue( post.
author() );
439 q.addBindValue( post.title() );
440 q.addBindValue( post.content() );
441 q.addBindValue( post.additionalContent() );
442 q.addBindValue( post.creationDateTime().
toString( KDateTime::ISODate ) );
443 q.addBindValue( post.modificationDateTime().
toString( KDateTime::ISODate ) );
444 q.addBindValue( post.isPrivate() );
445 q.addBindValue( post.isCommentAllowed() );
446 q.addBindValue( post.isTrackBackAllowed() );
447 q.addBindValue( post.link().url() );
448 q.addBindValue( post.permaLink().url() );
449 q.addBindValue( post.summary() );
450 q.addBindValue( post.slug() );
451 q.addBindValue( post.tags().join(QLatin1String(
",")) );
452 q.addBindValue( post.status() );
454 q.addBindValue( post.postId() );
455 q.addBindValue( blog_id );
458 d->mLastErrorText = q.lastError().text();
459 kDebug()<<
"Modifying post failed, SQL ERROR: "<< d->mLastErrorText;
465 qd.prepare( QLatin1String(
"DELETE FROM post_cat WHERE postId=? AND blogId=(SELECT blogid FROM blog where id=?)" ));
466 qd.addBindValue(post.postId());
467 qd.addBindValue(blog_id);
469 d->mLastErrorText = qd.lastError().text();
470 kDebug() <<
"Cannot delete previous categories.";
475 int cat_count = post.categories().count();
476 if( cat_count > 0 ) {
479 q2.prepare( QLatin1String(
"INSERT OR REPLACE INTO post_cat (blogId, postId, categoryId)\
480 VALUES((SELECT blogid FROM blog where id=?), ?, \
481 (SELECT categoryId FROM category WHERE name = ? AND blog_id= ?))" ) );
482 for (
int i = 0; i < cat_count; ++i ) {
483 q2.addBindValue(blog_id);
484 q2.addBindValue(post.postId());
485 q2.addBindValue(post.categories()[i]);
486 q2.addBindValue(blog_id);
488 d->mLastErrorText = q2.lastError().text();
489 kDebug() <<
"Cannot add one of categories to Post, SQL Error: " << q2.lastError().text();
500 q.prepare( QLatin1String(
"DELETE FROM post WHERE id=?" ));
501 q.addBindValue(
id );
504 d->mLastErrorText = q.lastError().text();
505 kDebug() << d->mLastErrorText;
513 q.prepare( QLatin1String(
"DELETE FROM post WHERE blog_id=? AND postId=?" ));
514 q.addBindValue( blog_id );
515 q.addBindValue( postId );
518 d->mLastErrorText = q.lastError().text();
519 kDebug() << d->mLastErrorText;
527 q.prepare( QLatin1String(
"DELETE FROM post WHERE blog_id=?") );
528 q.addBindValue( blog_id );
531 d->mLastErrorText = q.lastError().text();
532 kDebug() << q.lastError().text();
538 const QString &rssUrl,
const QString &categoryId,
const QString &parentId,
int blog_id )
541 q.prepare( QLatin1String(
"INSERT OR REPLACE INTO category (name, description, htmlUrl, rssUrl, categoryId, parentId, blog_id)\
542 VALUES(?, ?, ?, ?, ?, ?, ?)" ) );
543 q.addBindValue( name );
544 q.addBindValue( description );
545 q.addBindValue( htmlUrl );
546 q.addBindValue( rssUrl );
547 q.addBindValue( categoryId );
548 q.addBindValue( parentId );
549 q.addBindValue( blog_id );
552 return q.lastInsertId().toInt();
554 d->mLastErrorText = q.lastError().text();
562 q.prepare( QLatin1String(
"DELETE FROM category WHERE blog_id=?") );
563 q.addBindValue( blog_id );
566 d->mLastErrorText = q.lastError().text();
567 kDebug() << q.lastError().text();
572 int DBMan::addFile(
const QString& name,
int blog_id,
bool isUploaded,
const QString& localUrl,
const QString& remoteUrl )
577 q.prepare( QLatin1String(
"INSERT INTO file(name, blog_id, is_local, local_url, remote_url) VALUES(?, ?, ?, ?, ?)") );
578 q.addBindValue( name );
579 q.addBindValue( blog_id );
580 q.addBindValue( isUploaded );
582 q.addBindValue( localUrl );
583 q.addBindValue( remoteUrl );
586 return q.lastInsertId().toInt();
588 d->mLastErrorText = q.lastError().text();
596 q.prepare( QLatin1String(
"INSERT INTO file(name, blog_id, is_local, local_url, remote_url) VALUES(?, ?, ?, ?, ?)") );
597 q.addBindValue( file.
name() );
598 q.addBindValue( file.
blogId() );
604 return q.lastInsertId().toInt();
606 d->mLastErrorText = q.lastError().text();
614 q.prepare( QLatin1String(
"DELETE FROM file WHERE fileid=?") );
615 q.addBindValue( fileid );
618 d->mLastErrorText = q.lastError().text();
619 kDebug() << q.lastError().text();
627 q.prepare( QLatin1String(
"DELETE FROM file WHERE blog_id=?") );
628 q.addBindValue( blog_id );
631 d->mLastErrorText = q.lastError().text();
632 kDebug() << q.lastError().text();
639 return saveTemp_LocalEntry(post, blog_id, Local);
644 return saveTemp_LocalEntry(post, blog_id, Temp);
647 int DBMan::saveTemp_LocalEntry(
const BilboPost& basePost,
int blog_id, LocalPostState state )
653 QString postTable, postCatTable;
655 postTable = QLatin1String(
"local_post");
656 postCatTable = QLatin1String(
"local_post_cat");
658 postTable = QLatin1String(
"temp_post");
659 postCatTable = QLatin1String(
"temp_post_cat");
666 kDebug()<<
"Add new post to temp_post";
667 q.prepare( QLatin1String(
"INSERT OR REPLACE INTO ")+ postTable +QLatin1String(
" (postid, blog_id,\
668 author, title, content, text_more, c_time, m_time, is_private, is_comment_allowed,\
669 is_trackback_allowed, link, perma_link, summary, slug, tags, status)\
670 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ));
672 q.addBindValue( post.postId() );
673 q.addBindValue( blog_id );
674 q.addBindValue( post.
author() );
675 q.addBindValue( post.title() );
676 q.addBindValue( post.content() );
677 q.addBindValue( post.additionalContent() );
678 q.addBindValue( post.creationDateTime().
toString( KDateTime::ISODate ) );
679 q.addBindValue( post.creationDateTime().
toString( KDateTime::ISODate ) );
680 q.addBindValue( post.isPrivate() );
681 q.addBindValue( post.isCommentAllowed() );
682 q.addBindValue( post.isTrackBackAllowed() );
683 q.addBindValue( post.link().url() );
684 q.addBindValue( post.permaLink().url() );
685 q.addBindValue( post.summary() );
686 q.addBindValue( post.slug() );
687 q.addBindValue( post.tags().join(QLatin1String(
",")) );
688 q.addBindValue( post.status() );
691 localId = q.lastInsertId().toInt();
693 d->mLastErrorText = q.lastError().text();
694 kDebug() <<
"Cannot Add new local post to database!\n\tSQL Error: " << q.lastError().text();
699 kDebug()<<
"Update post, with id!";
700 q.prepare( QLatin1String(
"UPDATE ")+ postTable +QLatin1String(
" SET postid=?, blog_id=?,\
701 author=?, title=?, content=?, text_more=?, c_time=?, m_time=?, is_private=?, is_comment_allowed=?,\
702 is_trackback_allowed=?, link=?, perma_link=?, summary=?, slug=?, tags=?, status=?\
703 WHERE local_id=?" ));
705 q.addBindValue( post.postId() );
706 q.addBindValue( blog_id );
707 q.addBindValue( post.
author() );
708 q.addBindValue( post.title() );
709 q.addBindValue( post.content() );
710 q.addBindValue( post.additionalContent() );
711 q.addBindValue( post.creationDateTime().
toString( KDateTime::ISODate ) );
712 q.addBindValue( post.creationDateTime().
toString( KDateTime::ISODate ) );
713 q.addBindValue( post.isPrivate() );
714 q.addBindValue( post.isCommentAllowed() );
715 q.addBindValue( post.isTrackBackAllowed() );
716 q.addBindValue( post.link().url() );
717 q.addBindValue( post.permaLink().url() );
718 q.addBindValue( post.summary() );
719 q.addBindValue( post.slug() );
720 q.addBindValue( post.tags().join(QLatin1String(
",")) );
721 q.addBindValue( post.status() );
722 q.addBindValue( post.
localId() );
725 d->mLastErrorText = q.lastError().text();
726 kDebug() <<
"Cannot Add new local post to database!\n\tSQL Error: " << q.lastError().text();
767 qd.prepare( QLatin1String(
"DELETE FROM ") + postCatTable + QLatin1String(
" WHERE local_id=?") );
768 qd.addBindValue( localId );
770 d->mLastErrorText = q.lastError().text();
771 kDebug() <<
"Cannot delete previouse categories.";
776 int cat_count = post.categories().count();
777 if( cat_count > 0 ) {
780 q2.prepare( QLatin1String(
"INSERT OR REPLACE INTO ") + postCatTable + QLatin1String(
" (local_id, categoryId)\
781 VALUES(?, (SELECT categoryId FROM category WHERE name = ? AND blog_id= ?))" ) );
782 for (
int i = 0; i < cat_count; ++i ) {
783 q2.addBindValue(localId);
784 q2.addBindValue(post.categories()[i]);
785 q2.addBindValue(blog_id);
787 d->mLastErrorText = q.lastError().text();
788 kDebug() <<
"Cannot add one of categories to Post, SQL Error: " << q2.lastError().text();
800 q.prepare( QLatin1String(
"DELETE FROM local_post WHERE local_id=?") );
801 q.addBindValue( post.
localId() );
804 d->mLastErrorText = q.lastError().text();
805 kDebug() << d->mLastErrorText;
814 q.prepare( QLatin1String(
"DELETE FROM local_post WHERE local_id=?") );
815 q.addBindValue( local_id );
818 d->mLastErrorText = q.lastError().text();
819 kDebug() << d->mLastErrorText;
828 q.prepare( QLatin1String(
"DELETE FROM temp_post WHERE local_id=?") );
829 q.addBindValue( post.
localId() );
832 d->mLastErrorText = q.lastError().text();
833 kDebug() << q.lastError().text();
835 kDebug()<<
"Id: "<<post.
id()<<
"\tStatus: "<<post.status();
843 bool res = q.exec( QLatin1String(
"DELETE FROM temp_post") );
845 d->mLastErrorText = q.lastError().text();
846 kDebug() << q.lastError().text();
856 QList< BilboBlog *> DBMan::listBlogs()
858 QList<BilboBlog *> list;
860 if (q.exec( QLatin1String(
"SELECT id, blogid, blog_url, username, style_url, api_type, title,\
861 direction, local_directory, password FROM blog") ) ) {
864 tmp->
setId( q.value( 0 ).toInt() );
865 tmp->
setBlogId( q.value( 1 ).toString() );
866 tmp->
setUrl( QUrl( q.value( 2 ).toString() ) );
870 tmp->
setTitle( q.value( 6 ).toString() );
871 tmp->
setDirection(( Qt::LayoutDirection )q.value( 7 ).toInt() );
875 if ( d->mWallet && d->mWallet->readPassword( tmp->
url().url() + QLatin1Char(
'_') + tmp->
username() , buffer )
876 == 0 && !buffer.isEmpty() ) {
878 kDebug() <<
"Password loaded from kde wallet.";
886 d->mLastErrorText = q.lastError().text();
893 QMap< QString, int > list;
895 if( q.exec( QLatin1String(
"SELECT title, id FROM blog") ) ) {
897 list[q.value( 0 ).toString()] = q.value( 1 ).toInt();
900 d->mLastErrorText = q.lastError().text();
907 QList<BilboPost *> list;
909 q.prepare( QLatin1String(
"SELECT id, postid, author, title, content, c_time, m_time, is_private, is_comment_allowed,\
910 is_trackback_allowed, link, perma_link, summary, tags, status, text_more, slug\
911 FROM post WHERE blog_id = ? ORDER BY c_time DESC") );
912 q.addBindValue( blog_id );
916 tmp->
setId( q.value( 0 ).toInt() );
917 tmp->
setAuthor( q.value( 2 ).toString() );
918 tmp->setPostId( q.value( 1 ).toString() );
919 tmp->setTitle( q.value( 3 ).toString() );
920 tmp->setContent( q.value( 4 ).toString() );
921 tmp->setCreationDateTime( KDateTime::fromString( q.value( 5 ).toString(), KDateTime::ISODate ) );
922 tmp->setModificationDateTime( KDateTime::fromString( q.value( 6 ).toString(), KDateTime::ISODate ) );
923 tmp->setPrivate( q.value( 7 ).toBool() );
924 tmp->setCommentAllowed( q.value( 8 ).toBool() );
925 tmp->setTrackBackAllowed( q.value( 9 ).toBool() );
926 tmp->setLink( KUrl( q.value( 10 ).toString() ) );
927 tmp->setPermaLink( KUrl( q.value( 11 ).toString() ) );
928 tmp->setSummary( q.value( 12 ).toString() );
929 tmp->setTags( q.value( 13 ).toString().split( QLatin1Char(
','), QString::SkipEmptyParts ) );
930 tmp->setStatus(( KBlog::BlogPost::Status ) q.value( 14 ).toInt() );
931 tmp->setAdditionalContent( q.value( 15 ).toString() );
932 tmp->setSlug( q.value( 16 ).toString() );
935 QList<Category> catList;
937 q2.prepare( QLatin1String(
"SELECT category.name, category.description, category.htmlUrl, category.rssUrl,\
938 category.categoryId, category.parentId\
939 FROM category JOIN post_cat ON category.categoryId=post_cat.categoryId\
940 WHERE post_cat.postId = ? AND post_cat.blogId = (SELECT blogid FROM blog where id=?)" ) );
941 q2.addBindValue( tmp->postId() );
942 q2.addBindValue( blog_id );
944 while ( q2.next() ) {
947 cat.
name = q2.value( 0 ).toString();
949 cat.
htmlUrl = q2.value( 2 ).toString();
950 cat.
rssUrl = q2.value( 3 ).toString();
952 cat.
parentId = q2.value( 5 ).toString();
953 catList.append( cat );
956 d->mLastErrorText = q2.lastError().text();
962 d->mLastErrorText = q.lastError().text();
963 kDebug() <<
"Cannot get list of posts for blog with id " << blog_id <<
"error: "<< d->mLastErrorText;
972 q.prepare( QLatin1String(
"SELECT id, postid, author, title, content, c_time, m_time, is_private, is_comment_allowed,\
973 is_trackback_allowed, link, perma_link, summary, tags, status, blog_id, text_more, slug\
974 FROM post WHERE id = ?") );
975 q.addBindValue( post_id );
978 tmp.
setId( q.value( 0 ).toInt() );
979 tmp.
setAuthor( q.value( 2 ).toString() );
980 tmp.setPostId( q.value( 1 ).toString() );
981 tmp.setTitle( q.value( 3 ).toString() );
982 tmp.setContent( q.value( 4 ).toString() );
983 tmp.setCreationDateTime( KDateTime::fromString( q.value( 5 ).toString(), KDateTime::ISODate ) );
984 tmp.setModificationDateTime( KDateTime::fromString( q.value( 6 ).toString(), KDateTime::ISODate ) );
985 tmp.setPrivate( q.value( 7 ).toBool() );
986 tmp.setCommentAllowed( q.value( 8 ).toBool() );
987 tmp.setTrackBackAllowed( q.value( 9 ).toBool() );
988 QUrl u( q.value( 10 ).toString() );
990 QUrl pu( q.value( 11 ).toString() );
991 tmp.setPermaLink( pu );
992 tmp.setSummary( q.value( 12 ).toString() );
993 tmp.setTags( q.value( 13 ).toString().split( QLatin1Char(
','), QString::SkipEmptyParts ) );
994 tmp.setStatus(( KBlog::BlogPost::Status ) q.value( 14 ).toInt() );
995 int blog_id = q.value( 15 ).toInt();
996 tmp.setAdditionalContent( q.value( 16 ).toString() );
997 tmp.setSlug( q.value( 17 ).toString() );
1000 QList<Category> catList;
1002 q2.prepare( QLatin1String(
"SELECT category.name, category.description, category.htmlUrl, category.rssUrl,\
1003 category.categoryId, category.parentId, category.blog_id\
1004 FROM category JOIN post_cat ON category.categoryId=post_cat.categoryId\
1005 WHERE post_cat.postId = ? AND post_cat.blogId = (SELECT blogid FROM blog where id=?)") );
1006 q2.addBindValue( tmp.postId() );
1007 q2.addBindValue( blog_id );
1009 while ( q2.next() ) {
1011 cat.
blog_id = q2.value( 6 ).toInt();
1012 cat.
name = q2.value( 0 ).toString();
1014 cat.
htmlUrl = q2.value( 2 ).toString();
1015 cat.
rssUrl = q2.value( 3 ).toString();
1017 cat.
parentId = q2.value( 5 ).toString();
1018 catList.append( cat );
1021 d->mLastErrorText = q2.lastError().text();
1025 d->mLastErrorText = i18n(
"There is no post with the requested ID" );
1026 kDebug() <<
"There isn't any post with id: " << post_id;
1027 tmp.setStatus(KBlog::BlogPost::Error);
1030 d->mLastErrorText = q.lastError().text();
1031 kDebug() <<
"Cannot get post with id " << post_id;
1032 tmp.setStatus(KBlog::BlogPost::Error);
1040 QMap< int, QString >list;
1042 q.prepare( QLatin1String(
"SELECT title, id FROM post WHERE blog_id = ? ORDER BY c_time DESC") );
1043 q.addBindValue( blog_id );
1045 while ( q.next() ) {
1046 list.insert( q.value( 1 ).toInt(), q.value( 0 ).toString() );
1049 d->mLastErrorText = q.lastError().text();
1050 kDebug() <<
"Cannot get list of posts for blog with id " << blog_id;
1057 QList<QVariantMap> list;
1059 q.prepare( QLatin1String(
"SELECT title, id, c_time, is_private FROM post WHERE blog_id = ? ORDER BY c_time DESC") );
1060 q.addBindValue( blog_id );
1062 while ( q.next() ) {
1064 entry[ QLatin1String(
"title") ] = q.value( 0 ).toString();
1065 entry[ QLatin1String(
"id") ] = q.value( 1 ).toInt();
1066 entry[ QLatin1String(
"c_time") ] = KDateTime::fromString( q.value( 2 ).toString() ).dateTime();
1067 entry[ QLatin1String(
"is_private") ] = q.value( 3 ).toBool();
1071 d->mLastErrorText = q.lastError().text();
1072 kDebug() <<
"Cannot get list of posts for blog with id " << blog_id;
1079 QMap< QString, int > list;
1081 q.prepare( QLatin1String(
"SELECT name, catid FROM category WHERE blog_id = ?") );
1082 q.addBindValue( blog_id );
1084 while ( q.next() ) {
1085 list[q.value( 0 ).toString()] = q.value( 1 ).toInt();
1088 d->mLastErrorText = q.lastError().text();
1089 kDebug() <<
"Cannot get list of categories for blog with id " << blog_id;
1096 QList< Category > list;
1098 q.prepare( QLatin1String(
"SELECT catid, name, description, htmlUrl, rssUrl, categoryId, parentId FROM category\
1099 WHERE blog_id = ?") );
1100 q.addBindValue( blog_id );
1102 while ( q.next() ) {
1105 c.
id = q.value( 0 ).toInt();
1106 c.
name = q.value( 1 ).toString();
1108 c.
htmlUrl = q.value( 3 ).toString();
1109 c.
rssUrl = q.value( 4 ).toString();
1111 c.
parentId = q.value( 6 ).toString();
1115 d->mLastErrorText = q.lastError().text();
1116 kDebug() <<
"Cannot get list of categories for blog with id " << blog_id;
1123 QMap< QString, bool > list;
1125 q.prepare( QLatin1String(
"SELECT categoryId FROM category\
1126 WHERE blog_id = ?") );
1127 q.addBindValue( blog_id );
1129 while ( q.next() ) {
1130 list.insert( q.value( 0 ).toString(), false );
1133 d->mLastErrorText = q.lastError().text();
1134 kDebug() <<
"Cannot get list of categories for blog with id " << blog_id;
1141 QMap<BilboPost*, int> list;
1143 q.prepare( QLatin1String(
"SELECT local_id, id, postid, blog_id, author, title, content, text_more, c_time,\
1144 m_time, is_private, is_comment_allowed, is_trackback_allowed, link, perma_link, summary, tags, status,\
1145 slug FROM temp_post ORDER BY m_time DESC") );
1147 while ( q.next() ) {
1150 tmp->
setId( q.value( 1 ).toInt() );
1151 tmp->setPostId( q.value( 2 ).toString() );
1152 int blog_id = q.value( 3 ).toInt();
1153 tmp->
setAuthor( q.value( 4 ).toString() );
1154 tmp->setTitle( q.value( 5 ).toString() );
1155 tmp->setContent( q.value( 6 ).toString() );
1156 tmp->setCreationDateTime( KDateTime::fromString( q.value( 8 ).toString(), KDateTime::ISODate ) );
1157 tmp->setModificationDateTime( KDateTime::fromString( q.value( 9 ).toString(), KDateTime::ISODate ) );
1158 tmp->setPrivate( q.value( 10 ).toBool() );
1159 tmp->setCommentAllowed( q.value( 11 ).toBool() );
1160 tmp->setTrackBackAllowed( q.value( 12 ).toBool() );
1161 tmp->setLink( KUrl( q.value( 13 ).toString() ) );
1162 tmp->setPermaLink( KUrl( q.value( 14 ).toString() ) );
1163 tmp->setSummary( q.value( 15 ).toString() );
1164 tmp->setTags( q.value( 16 ).toString().split( QLatin1Char(
','), QString::SkipEmptyParts ) );
1165 tmp->setStatus(( KBlog::BlogPost::Status ) q.value( 17 ).toInt() );
1166 tmp->setSlug( q.value( 18 ).toString() );
1169 QList<Category> catList;
1171 q2.prepare( QLatin1String(
"SELECT category.name, category.description, category.htmlUrl, category.rssUrl,\
1172 category.categoryId, category.parentId\
1173 FROM category JOIN temp_post_cat ON category.categoryId=temp_post_cat.categoryId\
1174 WHERE temp_post_cat.local_id = ?") );
1175 q2.addBindValue( tmp->
localId() );
1178 while ( q2.next() ) {
1181 cat.
name = q2.value( 0 ).toString();
1183 cat.
htmlUrl = q2.value( 2 ).toString();
1184 cat.
rssUrl = q2.value( 3 ).toString();
1186 cat.
parentId = q2.value( 5 ).toString();
1187 catList.append( cat );
1190 list.insert( tmp, blog_id);
1192 d->mLastErrorText = q2.lastError().text();
1193 kDebug()<<
"Cannot get categories list of a post. SQL Error: "<< q2.lastError().text();
1197 d->mLastErrorText = q.lastError().text();
1198 kDebug() <<
"Cannot get list of temporary posts, SQL Error: "<< q.lastError().text();
1206 QList<QVariantMap> list;
1208 q.prepare( QLatin1String(
"SELECT local_post.local_id, local_post.title, local_post.blog_id, blog.title\
1209 FROM local_post LEFT JOIN blog ON local_post.blog_id = blog.id ORDER BY m_time DESC") );
1211 while ( q.next() ) {
1213 entry[ QLatin1String(
"local_id") ] = q.value( 0 ).toInt();
1214 entry[ QLatin1String(
"post_title") ] = q.value( 1 ).toString();
1215 entry[ QLatin1String(
"blog_id") ] = q.value( 2 ).toInt();
1216 entry[ QLatin1String(
"blog_title") ] = q.value( 3 ).toString();
1220 d->mLastErrorText = q.lastError().text();
1221 kDebug() <<
"Cannot get list of local posts. SQL Error: "<< q.lastError().text();
1230 q.prepare( QLatin1String(
"SELECT id, local_id, postid, blog_id, author, title, content, text_more, c_time,\
1231 m_time, is_private, is_comment_allowed, is_trackback_allowed, link, perma_link, summary, tags, status,\
1232 slug FROM local_post WHERE local_id=?") );
1233 q.addBindValue(local_id);
1236 tmp.
setId( q.value( 0 ).toInt() );
1238 tmp.setPostId( q.value( 2 ).toString() );
1239 int blog_id = q.value( 3 ).toInt();
1240 tmp.
setAuthor( q.value( 4 ).toString() );
1241 tmp.setTitle( q.value( 5 ).toString() );
1242 tmp.setContent( q.value( 6 ).toString() );
1243 tmp.setAdditionalContent( q.value( 7 ).toString() );
1244 tmp.setCreationDateTime( KDateTime::fromString( q.value( 8 ).toString(), KDateTime::ISODate ) );
1245 tmp.setModificationDateTime( KDateTime::fromString( q.value( 9 ).toString(), KDateTime::ISODate ) );
1246 tmp.setPrivate( q.value( 10 ).toBool() );
1247 tmp.setCommentAllowed( q.value( 11 ).toBool() );
1248 tmp.setTrackBackAllowed( q.value( 12 ).toBool() );
1249 tmp.setLink( KUrl( q.value( 13 ).toString() ) );
1250 tmp.setPermaLink( KUrl( q.value( 14 ).toString() ) );
1251 tmp.setSummary( q.value( 15 ).toString() );
1252 tmp.setTags( q.value( 16 ).toString().split( QLatin1Char(
','), QString::SkipEmptyParts ) );
1253 tmp.setStatus(( KBlog::BlogPost::Status ) q.value( 17 ).toInt() );
1254 tmp.setSlug( q.value( 18 ).toString() );
1257 QList<Category> catList;
1259 q2.prepare( QLatin1String(
"SELECT category.name, category.description, category.htmlUrl, category.rssUrl,\
1260 category.categoryId, category.parentId\
1261 FROM category JOIN local_post_cat ON category.categoryId=local_post_cat.categoryId\
1262 WHERE local_post_cat.local_id = ?") );
1263 q2.addBindValue( local_id );
1265 while ( q2.next() ) {
1268 cat.
name = q2.value( 0 ).toString();
1270 cat.
htmlUrl = q2.value( 2 ).toString();
1271 cat.
rssUrl = q2.value( 3 ).toString();
1273 cat.
parentId = q2.value( 5 ).toString();
1274 catList.append( cat );
1278 d->mLastErrorText = q2.lastError().text();
1279 kDebug()<<
"Cannot get categories list of local post. SQL Error: "<< q2.lastError().text();
1282 d->mLastErrorText = i18n(
"There is no local post with the requested ID " );
1283 kDebug()<<
"there isn't any local post with local_id "<<local_id;
1286 d->mLastErrorText = q.lastError().text();
1287 kDebug() <<
"Cannot get local post. SQL Error: "<< q.lastError().text();
QList< BilboPost * > listPosts(int blog_id)
bool clearCategories(int blog_id)
void setApi(const ApiType)
void setAuthor(const QString &)
bool removeLocalEntry(const BilboPost &post)
QMap< QString, bool > listCategoriesId(int blog_id)
QString lastErrorText() const
QString localDirectory() const
void setLocalId(const int)
void setTitle(const QString &)
int saveTempEntry(const BilboPost &post, int blog_id)
static DBMan * self()
Retrieve the instance of DataBase Manager.
Definition of a blog post! it's implemented to decrease dependency to KBlog :)
QList< QVariantMap > listLocalPosts()
Returns list of locally saved posts.
BilboBlog * blog(int blog_id)
QString as Title, and int as blog_id.
int saveLocalEntry(const BilboPost &post, int blog_id)
QMap< int, QString > listPostsTitle(int blog_id)
void setDirection(const Qt::LayoutDirection)
int addCategory(const QString &name, const QString &description, const QString &htmlUrl, const QString &rssUrl, const QString &categoryId, const QString &parentId, int blog_id)
Category:
void setPassword(const QString &)
void setUsername(const QString &)
QList< Category > listCategories(int blog_id)
QMap< QString, int > listBlogsTitle()
(BEGIN) Data retrieveing Functions:
BilboPost localPost(int local_id)
bool clearPosts(int blog_id)
void setUrl(const KUrl &)
bool editPost(const BilboPost &post, int blog_id)
const QMap< int, BilboBlog * > & blogList() const
bool removeTempEntry(const BilboPost &post)
QMap< BilboPost *, int > listTempPosts()
Returns list of temporary posts, e.g.
int addBlog(const BilboBlog &blog)
END.
bool clearFiles(int blog_id)
int addPost(const BilboPost &post, int blog_id)
Post:
Qt::LayoutDirection direction() const
QMap< QString, int > listCategoriesName(int blog_id)
bool editBlog(const BilboBlog &blog)
QList< QVariantMap > listPostsInfo(int blog_id)
QString as Title, and int as post_id.
void setLocalDirectory(const QString &)
static const char description[]
BilboPost getPostInfo(int post_id)
bool removeBlog(int blog_id)
KUrl url() const
returns blog xmlrpc Url! For http://bilbo.wordpress.com : it's url() is http://bilbo.wordpress.com/xmlrpc.php and it's blogUrl() is http://bilbo.wordpress.com/
QString blogUrl() const
return Blog Actual Url! For http://bilbo.wordpress.com : it's url() is http://bilbo.wordpress.com/xmlrpc.php and it's blogUrl() is http://bilbo.wordpress.com/
void setBlogId(const QString &)
bool removeFile(int fileid)
void setBlogUrl(const QString &blogUrl)
void setCategoryList(const QList< Category > &list)