39 #include <KToolInvocation>
42 #include <kstatusbar.h>
44 #include <kxmlguiwindow.h>
45 #include <kmessagebox.h>
46 #include <kdatetime.h>
49 class Toolbox::Private
52 QList<CatCheckBox*> listCategoryCheckBoxes;
54 KStatusBar *statusbar;
57 :
QWidget( parent ), d(new Private)
59 d->mCurrentBlogId = -1;
61 d->statusbar = qobject_cast<
KXmlGuiWindow*>( parent )->statusBar();
63 d->statusbar =
new KStatusBar(
this );
66 frameCat->layout()->setAlignment( Qt::AlignTop );
67 optionsDate->setDate( QDateTime::currentDateTime().date() );
68 optionsTime->setTime( QDateTime::currentDateTime().time() );
72 connect( btnEntriesClear, SIGNAL(clicked(
bool)),
this, SLOT(
clearEntries()) );
74 connect( lstEntriesList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
78 connect( btnOptionsNow, SIGNAL(clicked(
bool)),
this, SLOT(
setDateTimeNow()) );
79 connect( localEntries, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
83 lblOptionsTrackBack->setVisible(
false );
84 txtOptionsTrackback->setVisible(
false );
85 btnCatAdd->setVisible(
false );
87 lstEntriesList->setContextMenuPolicy( Qt::CustomContextMenu );
88 connect( lstEntriesList, SIGNAL(customContextMenuRequested(QPoint)),
102 if ( d->mCurrentBlogId == blog_id )
104 d->mCurrentBlogId = blog_id;
110 frameCat->setLayoutDirection( ll );
111 lstEntriesList->setLayoutDirection( ll );
116 if ( d->mCurrentBlogId == -1 ) {
117 KMessageBox::sorry(
this, i18n(
"No blog has been selected: you have to select a blog from the Blogs page before asking for the list of categories." ) );
125 d->statusbar->showMessage( i18n(
"Requesting list of categories..." ) );
131 if ( d->mCurrentBlogId == -1 ) {
132 KMessageBox::sorry(
this, i18n(
"No blog has been selected: you have to select a blog from the Blogs page before asking for the list of entries." ) );
139 if ( !dia->exec() ) {
143 count = dia->count();
150 connect( entryB, SIGNAL(
sigError(QString)),
this, SIGNAL(
sigError(QString)) );
151 d->statusbar->showMessage( i18n(
"Requesting list of entries..." ) );
152 setCursor( Qt::BusyCursor );
158 if ( blog_id == -1 ) {
159 kDebug() <<
"Blog Id doesn't set correctly";
162 lstEntriesList->clear();
164 const int count = listEntries.count();
165 for (
int i=0; i < count; ++i ) {
166 QListWidgetItem *lstItem =
new QListWidgetItem( listEntries[i].value(QLatin1String(
"title")).toString() );
167 lstItem->setToolTip(listEntries.at(i).value(QLatin1String(
"c_time")).toDateTime().toString());
168 if (listEntries.at(i).value(QLatin1String(
"is_private")).toBool()) {
169 lstItem->setForeground(QBrush(Qt::blue));
170 lstItem->setToolTip(i18n(
"%1 (Draft)",lstItem->toolTip()));
172 lstItem->setData( BlogEntryID, listEntries.at(i).value(QLatin1String(
"id")).toInt() );
173 lstEntriesList->addItem( lstItem );
175 d->statusbar->showMessage( i18n(
"List of entries received." ),
STATUSTIMEOUT );
182 if ( blog_id == -1 ) {
183 kDebug() <<
"Blog Id do not sets correctly";
187 QList<Category> listCategories;
190 QList<Category>::const_iterator i;
191 QList<Category>::const_iterator endIt = listCategories.constEnd();
192 for ( i = listCategories.constBegin(); i != endIt; ++i ) {
195 d->listCategoryCheckBoxes.append( cb );
196 frameCat->layout()->addWidget( cb );
198 d->statusbar->showMessage( i18n(
"List of categories received." ),
STATUSTIMEOUT );
205 if (lstEntriesList->selectedItems().count() < 1)
207 if ( KMessageBox::warningYesNoCancel(
this, i18n(
"Removing a post from your blog cannot be undone.\nAre you sure you want to remove the post with title \"%1\" from your blog?", lstEntriesList->currentItem()->text() ))
208 == KMessageBox::Yes) {
210 data(BlogEntryID).toInt() ) );
215 d->statusbar->showMessage( i18n(
"Removing post..." ) );
221 KMessageBox::information(
this, i18nc(
"Post removed from Blog",
"Post with title \"%1\" removed from \"%2\".",
224 d->statusbar->showMessage( i18n(
"Post removed" ),
STATUSTIMEOUT );
225 sender()->deleteLater();
230 KMessageBox::detailedError(
this, i18n(
"An error occurred in the latest transaction." ), errorMessage );
231 d->statusbar->showMessage( i18nc(
"Operation failed",
"Failed" ),
STATUSTIMEOUT );
232 sender()->deleteLater();
238 lstEntriesList->clear();
240 chkOptionsTime->setChecked(
false );
241 optionsDate->setDate( QDateTime::currentDateTime().date() );
242 optionsTime->setTime( QDateTime::currentDateTime().time() );
243 txtOptionsTrackback->clear();
246 chkOptionsComments->setChecked(
true );
247 chkOptionsTrackback->setChecked(
true );
248 comboOptionsStatus->setCurrentIndex( 0 );
255 chkOptionsTime->setChecked(
false );
256 optionsDate->setDate( QDateTime::currentDateTime().date() );
257 optionsTime->setTime( QDateTime::currentDateTime().time() );
258 txtOptionsTrackback->clear();
261 chkOptionsComments->setChecked(
true );
262 chkOptionsTrackback->setChecked(
true );
263 comboOptionsStatus->setCurrentIndex( 0 );
266 void Toolbox::clearCatList()
268 foreach(
CatCheckBox* cat, d->listCategoryCheckBoxes ){
271 d->listCategoryCheckBoxes.clear();
277 currentPost->setTags( currentTags() );
279 if ( currentPost->status() == KBlog::BlogPost::New ) {
280 if ( chkOptionsTime->isChecked() ) {
281 currentPost->setModificationDateTime( KDateTime( optionsDate->date(), optionsTime->time() ) );
282 currentPost->setCreationDateTime( KDateTime( optionsDate->date(), optionsTime->time() ) );
284 currentPost->setCreationDateTime( KDateTime::currentLocalDateTime() );
285 currentPost->setModificationDateTime( KDateTime::currentLocalDateTime() );
288 currentPost->setCreationDateTime( KDateTime( optionsDate->date(), optionsTime->time() ) );
289 currentPost->setModificationDateTime( KDateTime( optionsDate->date(), optionsTime->time() ) );
291 if ( currentPost->creationDateTime().isUtc() || currentPost->modificationDateTime().isUtc() ){
292 kDebug()<<
"creationDateTime was UTC!";
293 currentPost->setCreationDateTime( KDateTime( currentPost->creationDateTime().dateTime(),
294 KDateTime::LocalZone ) );
295 currentPost->setModificationDateTime( KDateTime( currentPost->modificationDateTime().dateTime(),
296 KDateTime::LocalZone ) );
298 currentPost->setSlug( txtSlug->text() );
299 currentPost->setPrivate(( comboOptionsStatus->currentIndex() == 1 ) ?
true :
false );
300 currentPost->setCommentAllowed( chkOptionsComments->isChecked() );
301 currentPost->setTrackBackAllowed( chkOptionsTrackback->isChecked() );
302 currentPost->setSummary( txtSummary->toPlainText() );
309 kDebug()<<
"post is NULL";
313 setSelectedCategories( post->categories() );
314 txtCatTags->setText( post->tags().join( QLatin1String(
", ") ) );
316 if ( post->status() == KBlog::BlogPost::New )
317 comboOptionsStatus->setCurrentIndex( 2 );
318 else if ( post->isPrivate() )
319 comboOptionsStatus->setCurrentIndex( 1 );
321 comboOptionsStatus->setCurrentIndex( 0 );
322 chkOptionsComments->setChecked( post->isCommentAllowed() );
323 chkOptionsTrackback->setChecked( post->isTrackBackAllowed() );
325 if ( post->creationDateTime().isUtc() || post->modificationDateTime().isUtc() ){
326 kDebug()<<
"creationDateTime was UTC!";
327 post->setCreationDateTime(KDateTime(post->creationDateTime().dateTime(), KDateTime::LocalZone));
328 post->setModificationDateTime(KDateTime(post->modificationDateTime().dateTime(), KDateTime::LocalZone));
330 optionsTime->setTime( post->creationDateTime().time() );
331 optionsDate->setDate( post->creationDateTime().date() );
332 txtSlug->setText( KUrl::fromPercentEncoding( post->slug().toLatin1() ) );
333 txtSummary->setPlainText( post->summary() );
336 QList< Category > Toolbox::selectedCategories()
const
338 QList<Category> list;
339 const int count = d->listCategoryCheckBoxes.count();
340 for (
int i = 0; i < count; ++i ) {
341 if ( d->listCategoryCheckBoxes.at(i)->isChecked() )
342 list.append( d->listCategoryCheckBoxes.at(i)->category() );
347 QStringList Toolbox::selectedCategoriesTitle()
const
350 const int count = d->listCategoryCheckBoxes.count();
351 for (
int i = 0; i < count; ++i ) {
352 if ( d->listCategoryCheckBoxes.at(i)->isChecked() )
353 list.append( d->listCategoryCheckBoxes.at(i)->category().name );
358 void Toolbox::setSelectedCategories(
const QStringList &list )
361 int count = d->listCategoryCheckBoxes.count();
362 for (
int i = 0; i < count; ++i ) {
363 if ( list.contains( d->listCategoryCheckBoxes.at(i)->category().name, Qt::CaseInsensitive ) )
364 d->listCategoryCheckBoxes.at(i)->setChecked(
true );
368 QStringList Toolbox::currentTags()
370 QStringList t = txtCatTags->text().split( QRegExp( QString::fromUtf8(
",|،") ), QString::SkipEmptyParts );
371 for (
int i = 0; i < t.count() ; ++i ) {
372 t[i] = t[i].trimmed();
380 kDebug() <<
"Emiting sigEntrySelected...";
386 box->setCurrentIndex( index );
391 if ( lstEntriesList->currentItem() == 0 ) {
395 if ( !post.permaLink().isEmpty() )
396 QApplication::clipboard()->setText( post.permaLink().prettyUrl() );
397 else if ( !post.link().isEmpty() )
398 QApplication::clipboard()->setText( post.link().prettyUrl() );
400 KMessageBox::sorry(
this, i18n(
"No link field is available in the database for this entry." ) );
403 void Toolbox::unCheckCatList()
405 const int count = d->listCategoryCheckBoxes.count();
406 for (
int j = 0; j < count; ++j ) {
407 d->listCategoryCheckBoxes.at(j)->setChecked(
false );
411 void Toolbox::setButtonsIcon()
413 btnEntriesUpdate->setIcon( KIcon( QLatin1String(
"view-refresh") ) );
414 btnEntriesRemove->setIcon( KIcon( QLatin1String(
"list-remove") ) );
415 btnEntriesClear->setIcon( KIcon( QLatin1String(
"edit-clear") ) );
416 btnCatReload->setIcon( KIcon( QLatin1String(
"view-refresh") ) );
417 btnCatAdd->setIcon( KIcon( QLatin1String(
"list-add") ) );
418 btnLocalRemove->setIcon( KIcon( QLatin1String(
"list-remove") ) );
426 localEntries->clear();
429 const int count = localList.count();
431 for (
int i=0; i < count; ++i){
432 const QString postTitle = localList.at(i).value( QLatin1String(
"post_title") ).toString();
433 const QString blogTitle = localList.at(i).value( QLatin1String(
"blog_title") ).toString();
435 QTreeWidgetItem *item =
new QTreeWidgetItem( localEntries, QStringList()<<postTitle<<blogTitle );
436 item->setData(0, LocalEntryID, localList.at(i).value( QLatin1String(
"local_id") ).toInt());
437 item->setData(1, LocalEntryID, localList.at(i).value( QLatin1String(
"blog_id") ).toInt());
443 kDebug()<<
"Emitting sigEntrySelected...";
451 if (localEntries->currentItem()) {
452 if ( KMessageBox::warningYesNo(
this, i18n(
"Are you sure you want to remove the selected local entry?"))
455 const int local_id = localEntries->currentItem()->data(0,LocalEntryID).toInt();
457 delete localEntries->currentItem();
459 KMessageBox::detailedError(
this, i18n(
"Cannot remove selected local entry."),
463 KMessageBox::sorry(
this, i18n(
"You have to select at least one entry from list."));
469 if ( d->mCurrentBlogId == -1 )
471 if ( KMessageBox::warningContinueCancel(
this, i18n(
"Are you sure you want to clear the list of entries?")) ==
472 KMessageBox::Cancel )
474 if (
DBMan::self()->clearPosts( d->mCurrentBlogId ) )
475 lstEntriesList->clear();
477 KMessageBox::detailedSorry(
this, i18n(
"Cannot clear the list of entries." ) ,
DBMan::self()->lastErrorText());
482 optionsDate->setDate( QDate::currentDate() );
483 optionsTime->setTime( QTime::currentTime() );
488 if ( lstEntriesList->selectedItems().isEmpty() )
491 KMenu *entriesContextMenu =
new KMenu;
492 KAction *actEntriesOpenInBrowser =
new KAction( KIcon(QLatin1String(
"applications-internet")),
493 i18n(
"Open in browser"), entriesContextMenu );
494 connect( actEntriesOpenInBrowser, SIGNAL(triggered()),
this, SLOT(
openPostInBrowser()) );
495 KAction *actEntriesCopyUrl =
new KAction( KIcon(QLatin1String(
"edit-copy")),
496 i18n(
"Copy URL"), entriesContextMenu );
497 connect( actEntriesCopyUrl, SIGNAL(triggered(
bool)),
this, SLOT(
slotEntriesCopyUrl()) );
498 KAction *actEntriesCopyTitle =
new KAction( KIcon(QLatin1String(
"edit-copy")),
499 i18n(
"Copy title"), entriesContextMenu );
500 connect( actEntriesCopyTitle, SIGNAL(triggered(
bool)),
this, SLOT(
copyPostTitle()) );
501 entriesContextMenu->addAction( actEntriesOpenInBrowser );
502 entriesContextMenu->addAction( actEntriesCopyUrl );
503 entriesContextMenu->addAction( actEntriesCopyTitle );
504 entriesContextMenu->exec( QCursor::pos() );
505 delete entriesContextMenu;
510 if ( lstEntriesList->selectedItems().isEmpty() )
514 if ( !post.permaLink().isEmpty() )
515 url = post.permaLink().pathOrUrl();
516 else if ( !post.link().isEmpty() )
517 url = post.link().pathOrUrl();
520 KToolInvocation::invokeBrowser ( url );
525 if ( !lstEntriesList->selectedItems().isEmpty() )
526 QApplication::clipboard()->setText( lstEntriesList->currentItem()->text() );
529 #include "toolbox.moc"
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.
static int updateEntriesCount()
Get updateEntriesCount.
void setModifyTimeStamp(bool willModify)
void removePost(BilboPost *post)
Remove an existing post from server.
static const int STATUSTIMEOUT
QList< Category > listCategories(int blog_id)
Extend QCheckBox to add property needed for Category checkboxes.
BilboPost localPost(int local_id)
void getEntriesListFromServer(int count)
retrieve latest posts from server
static bool showUpdateEntriesDialog()
Get showUpdateEntriesDialog.
const QMap< int, BilboBlog * > & blogList() const
void setCategory(const Category &category)
QList< QVariantMap > listPostsInfo(int blog_id)
QString as Title, and int as post_id.
void getCategoryListFromServer()
Request to Fetch categories list from server.
BilboPost getPostInfo(int post_id)
bool isModifyTimeStamp() const
void setCategoryList(const QList< Category > &list)