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

blogilo

  • sources
  • kde-4.12
  • kdepim
  • blogilo
  • src
mainwindow.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  Copyright (C) 2013 Laurent Montel <montel@kde.org>
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of
11  the License or (at your option) version 3 or any later version
12  accepted by the membership of KDE e.V. (or its successor approved
13  by the membership of KDE e.V.), which shall act as a proxy
14  defined in Section 14 of version 3 of the license.
15 
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, see http://www.gnu.org/licenses/
24 */
25 
26 #include "mainwindow.h"
27 #include "global.h"
28 #include "dbman.h"
29 #include "toolbox.h"
30 #include "postentry.h"
31 #include "addeditblog.h"
32 #include "backend.h"
33 #include "bilbomedia.h"
34 #include "settings.h"
35 #include "bilboblog.h"
36 #include "blogsettings.h"
37 #include "poststabwidget.h"
38 #include "uploadmediadialog.h"
39 
40 #include "ui_advancedsettingsbase.h"
41 #include "ui_settingsbase.h"
42 #include "ui_editorsettingsbase.h"
43 
44 #include <ktabwidget.h>
45 #include <KStatusNotifierItem>
46 #include <kstatusbar.h>
47 #include <KToggleAction>
48 #include <kactioncollection.h>
49 #include <kconfigdialog.h>
50 #include <kdebug.h>
51 #include <kmessagebox.h>
52 #include <KDE/KLocale>
53 #include <KSelectAction>
54 #include <kimagefilepreview.h>
55 #include <KToolInvocation>
56 #include <KMenu>
57 
58 
59 #include <QDir>
60 #include <QDockWidget>
61 #include <QProgressBar>
62 #include <QTimer>
63 #include <QKeyEvent>
64 
65 #define TIMEOUT 5000
66 
67 MainWindow::MainWindow()
68  : KXmlGuiWindow(),
69  activePost(0),
70  systemTray(0),
71  previousActivePostIndex(-1),
72  busyNumber(0),
73  progress(0),
74  mCurrentBlogId(__currentBlogId)
75 {
76  setWindowTitle( i18n("Blogilo") );
77 
78  tabPosts = new PostsTabWidget(this);
79  setCentralWidget( tabPosts );
80  connect(tabPosts,SIGNAL(createNewPost()),SLOT(slotCreateNewPost()));
81  connect(tabPosts,SIGNAL(closeTabClicked()),SLOT(slotCloseTabClicked()));
82  connect(tabPosts,SIGNAL(tabCloseRequested(int)), this, SLOT(slotRemovePostEntry(int)));
83  connect(tabPosts,SIGNAL(tabRemoveAllExclude(int)), this, SLOT(slotRemoveAllExclude(int)));
84 
85  toolbox = new Toolbox( this );
86  toolboxDock = new QDockWidget( i18n( "Toolbox" ), this );
87  toolboxDock->setAllowedAreas( Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea );
88  toolboxDock->setFeatures( QDockWidget::AllDockWidgetFeatures );
89  toolboxDock->setWidget( toolbox );
90 
91  toolboxDock->setObjectName( QLatin1String("dock_toolbox") );
92  toolbox->setObjectName( QLatin1String("toolbox") );
93 
94  this->addDockWidget( Qt::RightDockWidgetArea, toolboxDock );
95 
96  // then, setup our actions
97  setupActions();
98 
99  // add a status bar
100  statusBar()->show();
101 
102  // a call to KXmlGuiWindow::setupGUI() populates the GUI
103  // with actions, using KXMLGUI.
104  // It also applies the saved mainwindow settings, if any, and ask the
105  // mainwindow to automatically save settings if changed: window size,
106  // toolbar position, icon size, etc.
107  setupGUI();
108 
109  toolbox->setVisible( Settings::showToolboxOnStart() );
110  actionCollection()->action(QLatin1String("toggle_toolbox"))->setChecked( Settings::showToolboxOnStart() );
111 
112  setupSystemTray();
113 
114  connect( tabPosts, SIGNAL(currentChanged(int)), this, SLOT(slotActivePostChanged(int)) );
115  connect( toolbox, SIGNAL(sigEntrySelected(BilboPost&,int)), this, SLOT(slotNewPostOpened(BilboPost&,int)) );
116  connect( toolbox, SIGNAL(sigError(QString)), this, SLOT(slotError(QString)) );
117  connect( toolbox, SIGNAL(sigBusy(bool)), this, SLOT(slotBusy(bool)));
118 
119  QList<BilboBlog*> blogList = DBMan::self()->blogList().values();
120  const int count = blogList.count();
121  for(int i=0; i < count; ++i) {
122  QAction *act = new QAction( blogList.at(i)->title(), blogs );
123  act->setCheckable( true );
124  act->setData( blogList.at(i)->id() );
125  blogs->addAction( act );
126  }
127  connect( blogs, SIGNAL(triggered(QAction*)), this, SLOT(currentBlogChanged(QAction*)) );
128  QTimer::singleShot( 0, this, SLOT(loadTempPosts()) );
129 }
130 
131 MainWindow::~MainWindow()
132 {
133 }
134 
135 void MainWindow::slotCloseTabClicked()
136 {
137  const int currentIndex = tabPosts->currentIndex();
138  if (currentIndex != -1) {
139  slotRemovePostEntry(currentIndex);
140  }
141 }
142 
143 bool MainWindow::queryExit()
144 {
145  writeConfigs();
146  if ( !DBMan::self()->clearTempEntries() )
147  kDebug()<<"Could not erase temp_post table: "<< DBMan::self()->lastErrorText();
148  const int count = tabPosts->count();
149  if (count > 0) {
150  toolbox->getFieldsValue(activePost->currentPost());
151  for(int i =0; i<count; ++i) {
152  PostEntry* pst = qobject_cast<PostEntry*>(tabPosts->widget(i));
153  DBMan::self()->saveTempEntry(*pst->currentPost(), pst->currentPostBlogId());
154  }
155  }
156  return true;
157 }
158 
159 void MainWindow::setupActions()
160 {
161  KStandardAction::quit( qApp, SLOT(quit()), actionCollection() );
162 
163  KStandardAction::preferences( this, SLOT(optionsPreferences()), actionCollection() );
164 
165  // custom menu and menu item
166  KAction *actNewPost = new KAction( KIcon( QLatin1String("document-new") ), i18n( "New Post" ), this );
167  actionCollection()->addAction( QLatin1String( "new_post" ), actNewPost );
168  actNewPost->setShortcut( Qt::CTRL + Qt::Key_N );
169  connect( actNewPost, SIGNAL(triggered(bool)), this, SLOT(slotCreateNewPost()) );
170 
171  KAction *actAddBlog = new KAction( KIcon( QLatin1String("list-add") ), i18n( "Add Blog..." ), this );
172  actionCollection()->addAction( QLatin1String( "add_blog" ), actAddBlog );
173  connect( actAddBlog, SIGNAL(triggered(bool)), this, SLOT(addBlog()) );
174 
175  KAction *actPublish = new KAction( KIcon( QLatin1String("arrow-up") ), i18n( "Submit..." ), this );
176  actionCollection()->addAction( QLatin1String( "publish_post" ), actPublish );
177  connect( actPublish, SIGNAL(triggered(bool)), this, SLOT(slotPublishPost()) );
178 
179  KAction *actUpload = new KAction( KIcon( QLatin1String("upload-media") ), i18n( "Upload Media..." ), this );
180  actionCollection()->addAction( QLatin1String( "upload_media" ), actUpload );
181  connect( actUpload, SIGNAL(triggered(bool)), this, SLOT(uploadMediaObject()) );
182 
183  KAction *actSaveLocally = new KAction( KIcon( QLatin1String("document-save") ), i18n( "Save Locally" ), this );
184  actionCollection()->addAction( QLatin1String( "save_locally" ), actSaveLocally );
185  actSaveLocally->setShortcut( Qt::CTRL + Qt::Key_S );
186  connect( actSaveLocally, SIGNAL(triggered(bool)), this, SLOT(slotSavePostLocally()) );
187 
188  KToggleAction *actToggleToolboxVisible = new KToggleAction( i18n( "Show Toolbox" ), this );
189  actionCollection()->addAction( QLatin1String( "toggle_toolbox" ), actToggleToolboxVisible );
190  actToggleToolboxVisible->setShortcut( Qt::CTRL + Qt::Key_T );
191  connect( actToggleToolboxVisible, SIGNAL(toggled(bool)),
192  this, SLOT(slotToggleToolboxVisible(bool)) );
193  connect( toolboxDock, SIGNAL(visibilityChanged(bool)),
194  this, SLOT(slotToolboxVisibilityChanged(bool)) );
195 
196  blogs = new KSelectAction( this );
197  actionCollection()->addAction( QLatin1String( "blogs_list" ), blogs );
198 
199  KAction *actOpenBlog = new KAction(KIcon(QLatin1String("applications-internet")), i18n("Open in browser"), this);
200  actionCollection()->addAction( QLatin1String("open_blog_in_browser"), actOpenBlog);
201  actOpenBlog->setToolTip(i18n("Open current blog in browser"));
202  connect( actOpenBlog, SIGNAL(triggered(bool)), this, SLOT(slotOpenCurrentBlogInBrowser()) );
203 }
204 
205 void MainWindow::loadTempPosts()
206 {
207  kDebug();
208  QMap<BilboPost*, int> tempList = DBMan::self()->listTempPosts();
209  const int count = tempList.count();
210  if ( count > 0 ){
211  QMap<BilboPost*, int>::ConstIterator it = tempList.constBegin();
212  QMap<BilboPost*, int>::ConstIterator endIt = tempList.constEnd();
213  for( ; it != endIt; ++it ) {
214  createPostEntry(it.value(), (*it.key()));
215  }
216  } else {
217  slotCreateNewPost();
218  }
219 // activePost = qobject_cast<PostEntry*>( tabPosts->currentWidget() );
220  previousActivePostIndex = 0;
221  if ( activePost )
222  setCurrentBlog( activePost->currentPostBlogId() );
223 }
224 
225 void MainWindow::setCurrentBlog( int blog_id )
226 {
227  kDebug()<<blog_id;
228  if (blog_id == -1) {
229  blogs->setCurrentItem( -1 );
230  toolbox->setCurrentBlogId( blog_id );
231 // actionCollection()->action("publish_post")->setEnabled( false );
232  return;
233  }
234  const int count = blogs->items().count();
235  for (int i=0; i<count; ++i) {
236  if ( blogs->action(i)->data().toInt() == blog_id ) {
237  blogs->setCurrentItem( i );
238  currentBlogChanged( blogs->action( i ) );
239  break;
240  }
241  }
242 }
243 
244 void MainWindow::currentBlogChanged( QAction *act )
245 {
246  if ( act ) {
247  if ( mCurrentBlogId == act->data().toInt() )
248  return;
249  mCurrentBlogId = act->data().toInt();
250 // __currentBlogId = mCurrentBlogId;
251  if ( activePost ) {
252 // actionCollection()->action("publish_post")->setEnabled( true );
253  activePost->setCurrentPostBlogId( mCurrentBlogId );
254  } else {
255 // actionCollection()->action("publish_post")->setEnabled( false );
256  }
257  blogs->setToolTip( DBMan::self()->blogList().value( mCurrentBlogId )->blogUrl() );
258  } else {
259  mCurrentBlogId = -1;
260  if ( activePost )
261  activePost->setCurrentPostBlogId( mCurrentBlogId );
262  }
263  toolbox->setCurrentBlogId( mCurrentBlogId );
264 }
265 
266 void MainWindow::slotCreateNewPost()
267 {
268  kDebug();
269 
270  tabPosts->setCurrentWidget( createPostEntry( mCurrentBlogId, BilboPost()) );
271  if ( mCurrentBlogId == -1 ) {
272  if ( !blogs->items().isEmpty() ) {
273  blogs->setCurrentItem( 0 );
274  currentBlogChanged( blogs->action( 0 ) );
275  }
276  }
277  if ( this->isVisible() == false ) {
278  this->show();
279  }
280 }
281 
282 void MainWindow::optionsPreferences()
283 {
284  // The preference dialog is derived from prefs_base.ui
285  //
286  // compare the names of the widgets in the .ui file
287  // to the names of the variables in the .kcfg file
288  //avoid having 2 dialogs shown
289  if ( KConfigDialog::showDialog( QLatin1String("settings") ) ) {
290  return;
291  }
292  KConfigDialog *dialog = new KConfigDialog( this, QLatin1String("settings"), Settings::self() );
293  QWidget *generalSettingsDlg = new QWidget;
294  generalSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
295  Ui::SettingsBase ui_prefs_base;
296  Ui::EditorSettingsBase ui_editorsettings_base;
297  ui_prefs_base.setupUi( generalSettingsDlg );
298  BlogSettings *blogSettingsDlg = new BlogSettings;
299  blogSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
300  connect( blogSettingsDlg, SIGNAL(blogAdded(BilboBlog)),
301  this, SLOT(slotBlogAdded(BilboBlog)) );
302  connect( blogSettingsDlg, SIGNAL(blogEdited(BilboBlog)),
303  this, SLOT(slotBlogEdited(BilboBlog)) );
304  connect( blogSettingsDlg, SIGNAL(blogRemoved(int)), this, SLOT(slotBlogRemoved(int)) );
305  QWidget *editorSettingsDlg = new QWidget;
306  editorSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
307  ui_editorsettings_base.setupUi( editorSettingsDlg );
308  QWidget *advancedSettingsDlg = new QWidget;
309  advancedSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
310  Ui::AdvancedSettingsBase ui_advancedsettings_base;
311  ui_advancedsettings_base.setupUi( advancedSettingsDlg );
312 
313  dialog->addPage( generalSettingsDlg, i18nc( "Configure Page", "General" ), QLatin1String("configure") );
314  dialog->addPage( blogSettingsDlg, i18nc( "Configure Page", "Blogs" ), QLatin1String("document-properties"));
315  dialog->addPage( editorSettingsDlg, i18nc( "Configure Page", "Editor" ), QLatin1String("accessories-text-editor"));
316  dialog->addPage( advancedSettingsDlg, i18nc( "Configure Page", "Advanced" ), QLatin1String("applications-utilities"));
317  connect( dialog, SIGNAL(settingsChanged(QString)), this, SIGNAL(settingsChanged()) );
318  connect( dialog, SIGNAL(settingsChanged(QString)), this, SLOT(slotSettingsChanged()) );
319  connect( dialog, SIGNAL(destroyed(QObject*)), this, SLOT(slotDialogDestroyed(QObject*)));
320  dialog->setAttribute( Qt::WA_DeleteOnClose );
321  dialog->resize( Settings::configWindowSize() );
322  dialog->show();
323 }
324 
325 void MainWindow::slotSettingsChanged()
326 {
327  setupSystemTray();
328 }
329 
330 void MainWindow::slotDialogDestroyed( QObject *win )
331 {
332  const QSize size = qobject_cast<QWidget *>(win)->size();
333  const QString name = win->objectName();
334  if (name == QLatin1String("settings")) {
335  Settings::setConfigWindowSize( size );
336  }
337 }
338 
339 void MainWindow::addBlog()
340 {
341  AddEditBlog *addEditBlogWindow = new AddEditBlog( -1, this );
342  addEditBlogWindow->setWindowModality( Qt::ApplicationModal );
343  addEditBlogWindow->setAttribute( Qt::WA_DeleteOnClose );
344  connect( addEditBlogWindow, SIGNAL(sigBlogAdded(BilboBlog)),
345  this, SLOT(slotBlogAdded(BilboBlog)) );
346  addEditBlogWindow->show();
347 }
348 
349 void MainWindow::slotBlogAdded( const BilboBlog &blog )
350 {
351  QAction *act = new QAction( blog.title(), blogs );
352  act->setCheckable( true );
353  act->setData( blog.id() );
354  blogs->addAction( act );
355  blogs->setCurrentAction( act );
356  currentBlogChanged( act );
357  toolbox->slotReloadCategoryList();
358  toolbox->slotUpdateEntries( 20 );
359 }
360 
361 void MainWindow::slotBlogEdited( const BilboBlog &blog )
362 {
363  const int count = blogs->actions().count();
364  for(int i=0; i< count; ++i){
365  if ( blogs->action( i )->data().toInt() == blog.id() ) {
366  blogs->action( i )->setText( blog.title() );
367  break;
368  }
369  }
370 }
371 
372 void MainWindow::slotBlogRemoved( int blog_id )
373 {
374  const int count = blogs->actions().count();
375  for(int i=0; i< count; ++i){
376  if ( blogs->action( i )->data().toInt() == blog_id ) {
377  if ( blogs->currentItem() == i ) {
378  blogs->setCurrentItem( i-1 );
379  currentBlogChanged( blogs->action( i-1 ) );
380  }
381  blogs->removeAction( blogs->action( i ) );
382  if (blogs->currentItem() == -1)
383  toolbox->clearFields();
384  break;
385  }
386  }
387 }
388 
389 void MainWindow::setupSystemTray()
390 {
391  if ( Settings::enableSysTrayIcon()) {
392  if ( !systemTray ) {
393  systemTray = new KStatusNotifierItem( this );
394  systemTray->setIconByName(QLatin1String("blogilo"));
395  systemTray->setToolTip( QLatin1String("blogilo"), i18n("Blogilo"), i18n("A KDE Blogging Client") );
396  systemTray->contextMenu()->addAction( actionCollection()->action(QLatin1String("new_post")) );
397  systemTray->setCategory(KStatusNotifierItem::ApplicationStatus);
398  systemTray->setStatus(KStatusNotifierItem::Active);
399  }
400  } else if ( systemTray ) {
401  systemTray->deleteLater();
402  systemTray = 0;
403  }
404 }
405 
406 void MainWindow::slotPostTitleChanged( const QString& title )
407 {
408 // kDebug();
409  tabPosts->setTabText( tabPosts->currentIndex(), title );
410 }
411 
412 void MainWindow::slotToggleToolboxVisible( bool isVisible )
413 {
414  toolboxDock->setVisible( isVisible );
415 }
416 
417 void MainWindow::slotToolboxVisibilityChanged(bool)
418 {
419  actionCollection()->action(QLatin1String("toggle_toolbox"))->setChecked( toolboxDock->isVisibleTo(this) );
420 }
421 
422 void MainWindow::slotActivePostChanged( int index )
423 {
424  kDebug() << "new post index: " << index << "\tPrev Index: " << previousActivePostIndex;
425 
426  activePost = qobject_cast<PostEntry*>( tabPosts->widget( index ) );
427  PostEntry *prevActivePost = qobject_cast<PostEntry*>( tabPosts->widget( previousActivePostIndex ) );
428  int activePostBlogId = -1;
429  int prevPostBlogId = -1;
430 
431  if (( prevActivePost != 0 ) && ( index != previousActivePostIndex ) ) {
432  prevPostBlogId = prevActivePost->currentPostBlogId();
433  toolbox->getFieldsValue( prevActivePost->currentPost() );
434  prevActivePost->setCurrentPostBlogId( mCurrentBlogId );
435  }
436 
437  if ( index >= 0 ) {
438  activePostBlogId = activePost->currentPostBlogId();
439  if ( activePostBlogId != -1 && activePostBlogId != prevPostBlogId ) {
440  setCurrentBlog( activePostBlogId );
441  }
442  toolbox->setFieldsValue( activePost->currentPost() );
443  } else {
444  kError() << "ActivePost is NULL! tabPosts Current index is: " << tabPosts->currentIndex() ;
445  }
446  previousActivePostIndex = index;
447 }
448 
449 void MainWindow::slotPublishPost()
450 {
451  kDebug();
452  if ( mCurrentBlogId == -1 ) {
453  KMessageBox::sorry( this, i18n( "You have to select a blog to publish this post to." ) );
454  return;
455  }
456  if ( !activePost || tabPosts->currentIndex() == -1) {
457  KMessageBox::sorry( this, i18n( "There is no open post to submit." ) );
458  return;
459  }
460  toolbox->getFieldsValue( activePost->currentPost() );
461  activePost->submitPost( mCurrentBlogId, *activePost->currentPost() );
462 }
463 
464 void MainWindow::slotRemoveAllExclude(int pos)
465 {
466  for(int i = tabPosts->count()-1; i >=0; --i) {
467  if (i == pos) {
468  continue;
469  }
470  PostEntry *widget = qobject_cast<PostEntry*>( tabPosts->widget( i ) );
471  if ( !widget ) {
472  if ( activePost )
473  widget = activePost;
474  else
475  return;
476  }
477  DBMan::self()->removeTempEntry( *widget->currentPost() );
478  tabPosts->removePage(widget);
479  widget->close();
480  }
481  if ( tabPosts->count() < 1 ) {
482  activePost = 0;
483  toolbox->resetFields();
484 // actionCollection()->action("publish_post")->setEnabled( false );
485  }
486 }
487 
488 void MainWindow::slotRemovePostEntry( int pos )
489 {
490  kDebug();
491 
492  PostEntry *widget = qobject_cast<PostEntry*>( tabPosts->widget( pos ) );
493 
494  if ( !widget ) {
495  if ( activePost )
496  widget = activePost;
497  else
498  return;
499  }
500  DBMan::self()->removeTempEntry( *widget->currentPost() );
501  tabPosts->removePage(widget);
502  widget->close();
503 
504  if ( tabPosts->count() < 1 ) {
505  activePost = 0;
506  toolbox->resetFields();
507 // actionCollection()->action("publish_post")->setEnabled( false );
508  }
509 }
510 
511 void MainWindow::slotNewPostOpened( BilboPost &newPost, int blog_id )
512 {
513  kDebug();
514  QWidget * w = createPostEntry( blog_id, newPost );
515  tabPosts->setCurrentWidget( w );
516 }
517 
518 void MainWindow::slotSavePostLocally()
519 {
520  kDebug();
521  if (activePost && (tabPosts->count() > 0)) {
522  toolbox->getFieldsValue(activePost->currentPost());
523  activePost->saveLocally();
524  toolbox->reloadLocalPosts();
525  }
526 }
527 
528 void MainWindow::slotError( const QString & errorMessage )
529 {
530  kDebug() << "Error message: " << errorMessage;
531  KMessageBox::detailedError( this, i18n( "An error occurred in the last transaction." ), errorMessage );
532  statusBar()->clearMessage();
533  slotBusy(false);
534 }
535 
536 void MainWindow::writeConfigs()
537 {
538  kDebug();
539  if ( toolboxDock->isVisible() )
540  Settings::setShowToolboxOnStart( true );
541  else
542  Settings::setShowToolboxOnStart( false );
543 }
544 
545 void MainWindow::keyPressEvent( QKeyEvent * event )
546 {
547  if ( event->modifiers() == Qt::CTRL ) {
548  switch ( event->key() ) {
549  case Qt::Key_1:
550  toolbox->setCurrentPage( 0 );
551  break;
552  case Qt::Key_2:
553  toolbox->setCurrentPage( 1 );
554  break;
555  case Qt::Key_3:
556  toolbox->setCurrentPage( 2 );
557  break;
558  case Qt::Key_4:
559  toolbox->setCurrentPage( 3 );
560  break;
561  case Qt::Key_5:
562  toolbox->setCurrentPage( 4 );
563  break;
564  case Qt::Key_W:
565  slotRemovePostEntry( tabPosts->currentIndex() );
566  break;
567  default:
568  KXmlGuiWindow::keyPressEvent( event );
569  break;
570  }
571  }
572 }
573 
574 void MainWindow::postManipulationDone( bool isError, const QString &customMessage )
575 {
576  kDebug();
577  if (isError){
578  KMessageBox::detailedError(this, i18n("Submitting post failed"), customMessage);
579  } else {
580  PostEntry *entry = qobject_cast<PostEntry*>(sender());
581  if (entry){
582  if (KMessageBox::questionYesNo(this, i18n("%1\nDo you want to keep the post open?", customMessage),
583  QString(), KStandardGuiItem::yes(), KStandardGuiItem::no(), QLatin1String("KeepPostOpen")) == KMessageBox::No ) {
584  slotRemovePostEntry( tabPosts->indexOf( entry ) );
585  } else {
586  toolbox->setFieldsValue(entry->currentPost());
587  }
588  }
589  toolbox->slotLoadEntriesFromDB( mCurrentBlogId );
590  }
591  this->unsetCursor();
592  toolbox->unsetCursor();
593 }
594 
595 void MainWindow::slotBusy(bool isBusy)
596 {
597  kDebug()<<"isBusy="<<isBusy<<"\tbusyNumber="<<busyNumber;
598  if (isBusy){
599  this->setCursor(Qt::BusyCursor);
600  toolbox->setCursor( Qt::BusyCursor );
601  ++busyNumber;
602  if (!progress){
603  progress = new QProgressBar(statusBar());
604  progress->setMinimum( 0 );
605  progress->setMaximum( 0 );
606  progress->setFixedSize(250, 17);
607  statusBar()->addPermanentWidget(progress);
608  }
609  } else {
610  --busyNumber;
611  if ( busyNumber < 1 ){
612  this->unsetCursor();
613  toolbox->unsetCursor();
614  if (progress){
615  statusBar()->removeWidget(progress);
616  progress->deleteLater();
617  progress = 0;
618  }
619 // busyNumber = 0;
620  }
621  }
622 }
623 
624 QWidget* MainWindow::createPostEntry(int blog_id, const BilboPost& post)
625 {
626  kDebug();
627  PostEntry *temp = new PostEntry( this );
628  temp->setAttribute( Qt::WA_DeleteOnClose );
629  temp->setCurrentPost(post);
630  temp->setCurrentPostBlogId( blog_id );
631 
632  connect( temp, SIGNAL(postTitleChanged(QString)),
633  this, SLOT(slotPostTitleChanged(QString)) );
634  connect( temp, SIGNAL(postPublishingDone(bool,QString)),
635  this, SLOT(postManipulationDone(bool,QString)) );
636  connect( this, SIGNAL(settingsChanged()), temp, SLOT(settingsChanged()));
637  connect( temp, SIGNAL(showStatusMessage(QString,bool)),
638  this, SLOT(slotShowStatusMessage(QString,bool)));
639 
640  connect( temp, SIGNAL(sigBusy(bool)), this, SLOT(slotBusy(bool)) );
641 
642  tabPosts->addTab( temp, post.title() );
643  return temp;
644 }
645 
646 void MainWindow::slotShowStatusMessage(const QString &message, bool isPermanent)
647 {
648  statusBar()->showMessage(message, (isPermanent ? 0 : TIMEOUT));
649 }
650 
651 void MainWindow::uploadMediaObject()
652 {
653  UploadMediaDialog *uploadDlg = new UploadMediaDialog(this);
654  connect(uploadDlg, SIGNAL(sigBusy(bool)), SLOT(slotBusy(bool)));
655  if (mCurrentBlogId == -1)
656  uploadDlg->init( 0 );
657  else
658  uploadDlg->init( DBMan::self()->blog(mCurrentBlogId) );
659 }
660 
661 void MainWindow::slotOpenCurrentBlogInBrowser()
662 {
663  if (mCurrentBlogId > -1) {
664  KUrl url( DBMan::self()->blog( mCurrentBlogId )->blogUrl() );
665  if (url.isValid())
666  KToolInvocation::invokeBrowser(url.url());
667  else
668  KMessageBox::sorry(this, i18n("Cannot find current blog URL."));
669  }
672 }
673 
674 #include "mainwindow.moc"
MainWindow::slotError
void slotError(const QString &errorMessage)
Definition: mainwindow.cpp:528
postentry.h
Toolbox::clearFields
void clearFields()
Definition: toolbox.cpp:235
Toolbox::setFieldsValue
void setFieldsValue(BilboPost *post=0)
Definition: toolbox.cpp:305
MainWindow::slotCreateNewPost
void slotCreateNewPost()
Definition: mainwindow.cpp:266
MainWindow::slotSettingsChanged
void slotSettingsChanged()
Definition: mainwindow.cpp:325
Toolbox::reloadLocalPosts
void reloadLocalPosts()
Definition: toolbox.cpp:422
MainWindow::slotPostTitleChanged
void slotPostTitleChanged(const QString &title)
Definition: mainwindow.cpp:406
blogsettings.h
TIMEOUT
#define TIMEOUT
Definition: mainwindow.cpp:65
Settings::showToolboxOnStart
static bool showToolboxOnStart()
Get showToolboxOnStart.
Definition: settings.h:50
Toolbox::slotLoadEntriesFromDB
void slotLoadEntriesFromDB(int blog_id)
Definition: toolbox.cpp:156
PostsTabWidget
Definition: poststabwidget.h:24
MainWindow::slotNewPostOpened
void slotNewPostOpened(BilboPost &newPost, int blog_id)
Definition: mainwindow.cpp:511
DBMan::lastErrorText
QString lastErrorText() const
Definition: dbman.cpp:100
Settings::enableSysTrayIcon
static bool enableSysTrayIcon()
Get enableSysTrayIcon.
Definition: settings.h:21
MainWindow::uploadMediaObject
void uploadMediaObject()
Definition: mainwindow.cpp:651
MainWindow::addBlog
void addBlog()
Definition: mainwindow.cpp:339
QWidget
MainWindow::slotToolboxVisibilityChanged
void slotToolboxVisibilityChanged(bool isVisible)
Definition: mainwindow.cpp:417
Settings::setShowToolboxOnStart
static void setShowToolboxOnStart(bool v)
Set showToolboxOnStart.
Definition: settings.h:40
Settings::setConfigWindowSize
static void setConfigWindowSize(const QSize &v)
Set configWindowSize.
Definition: settings.h:59
DBMan::saveTempEntry
int saveTempEntry(const BilboPost &post, int blog_id)
Definition: dbman.cpp:642
Settings::configWindowSize
static QSize configWindowSize()
Get configWindowSize.
Definition: settings.h:69
Toolbox::slotUpdateEntries
void slotUpdateEntries(int count=0)
Definition: toolbox.cpp:129
BilboBlog::title
QString title() const
Definition: bilboblog.cpp:161
DBMan::self
static DBMan * self()
Retrieve the instance of DataBase Manager.
Definition: dbman.cpp:107
BilboPost
Definition of a blog post! it's implemented to decrease dependency to KBlog :)
Definition: bilbopost.h:41
QObject
global.h
MainWindow::queryExit
virtual bool queryExit()
Definition: mainwindow.cpp:143
Settings::self
static Settings * self()
Definition: settings.cpp:17
UploadMediaDialog
Definition: uploadmediadialog.h:33
BilboBlog
Blog definition class!
Definition: bilboblog.h:40
uploadmediadialog.h
KXmlGuiWindow
__currentBlogId
int __currentBlogId
Global variables.
Definition: global.cpp:29
Toolbox
Definition: toolbox.h:37
Toolbox::setCurrentBlogId
void setCurrentBlogId(int blog_id)
Definition: toolbox.cpp:100
mainwindow.h
MainWindow::slotPublishPost
void slotPublishPost()
Definition: mainwindow.cpp:449
addeditblog.h
Toolbox::slotReloadCategoryList
void slotReloadCategoryList()
Definition: toolbox.cpp:114
Toolbox::setCurrentPage
void setCurrentPage(int index)
Definition: toolbox.cpp:384
bilbomedia.h
PostEntry
Post Entry Widget contains Editor, and Title box.
Definition: postentry.h:40
MainWindow::slotActivePostChanged
void slotActivePostChanged(int tabIndex)
Definition: mainwindow.cpp:422
bilboblog.h
MainWindow::settingsChanged
void settingsChanged()
toolbox.h
MainWindow::slotRemovePostEntry
void slotRemovePostEntry(int post)
Remove widget at position pos from main tab wigdet.
Definition: mainwindow.cpp:488
MainWindow::keyPressEvent
void keyPressEvent(QKeyEvent *event)
Definition: mainwindow.cpp:545
DBMan::blogList
const QMap< int, BilboBlog * > & blogList() const
Definition: dbman.cpp:114
DBMan::removeTempEntry
bool removeTempEntry(const BilboPost &post)
Definition: dbman.cpp:824
DBMan::listTempPosts
QMap< BilboPost *, int > listTempPosts()
Returns list of temporary posts, e.g.
Definition: dbman.cpp:1139
dbman.h
MainWindow::MainWindow
MainWindow()
Definition: mainwindow.cpp:67
BilboBlog::id
int id() const
Definition: bilboblog.cpp:213
settings.h
Toolbox::getFieldsValue
void getFieldsValue(BilboPost *currentPost)
Will set current state of toolbox (Current post) properties on input pointer!
Definition: toolbox.cpp:274
MainWindow::slotOpenCurrentBlogInBrowser
void slotOpenCurrentBlogInBrowser()
Definition: mainwindow.cpp:661
MainWindow::slotToggleToolboxVisible
void slotToggleToolboxVisible(bool isVisible)
Definition: mainwindow.cpp:412
PostEntry::currentPostBlogId
int currentPostBlogId() const
Definition: postentry.cpp:285
poststabwidget.h
UploadMediaDialog::init
void init(const BilboBlog *currentBlog)
Definition: uploadmediadialog.cpp:67
BlogSettings
Definition: blogsettings.h:32
MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:131
MainWindow::loadTempPosts
void loadTempPosts()
To open temporary posts and that posts are open at previous quit.
Definition: mainwindow.cpp:205
PostEntry::currentPost
BilboPost * currentPost()
Definition: postentry.cpp:309
Toolbox::resetFields
void resetFields()
Definition: toolbox.cpp:251
backend.h
PostEntry::setCurrentPost
void setCurrentPost(const BilboPost &post)
Definition: postentry.cpp:315
AddEditBlog
Definition: addeditblog.h:43
MainWindow::slotSavePostLocally
void slotSavePostLocally()
Definition: mainwindow.cpp:518
PostEntry::setCurrentPostBlogId
void setCurrentPostBlogId(int blog_id)
Definition: postentry.cpp:290
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:44 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

blogilo

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal