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

blogilo

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

KDE's Doxygen guidelines are available online.

blogilo

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

kdepim API Reference

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

Search



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

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