42 #include "ui_advancedsettingsbase.h"
43 #include "ui_settingsbase.h"
44 #include "ui_editorsettingsbase.h"
46 #include "pimcommon/storageservice/storageservicemanager.h"
47 #include "pimcommon/storageservice/storageservicejobconfig.h"
48 #include "pimcommon/storageservice/storageserviceabstract.h"
49 #include "pimcommon/storageservice/storageserviceprogressmanager.h"
51 #include "libkdepim/progresswidget/progressdialog.h"
52 #include "libkdepim/progresswidget/statusbarprogresswidget.h"
53 #include "libkdepim/progresswidget/progressstatusbarwidget.h"
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>
63 #include <kmessagebox.h>
65 #include <KSelectAction>
66 #include <kimagefilepreview.h>
67 #include <KToolInvocation>
70 #include <QDockWidget>
71 #include <QProgressBar>
81 previousActivePostIndex(-1),
86 setWindowTitle( i18n(
"Blogilo") );
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)));
97 toolboxDock =
new QDockWidget( i18n(
"Toolbox" ),
this );
98 toolboxDock->
setAllowedAreas( Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea );
99 toolboxDock->
setFeatures( QDockWidget::AllDockWidgetFeatures );
105 this->addDockWidget( Qt::RightDockWidgetArea, toolboxDock );
118 toolbox->
setVisible( Settings::showToolboxOnStart() );
119 actionCollection()->action(
QLatin1String(
"toggle_toolbox"))->setChecked( Settings::showToolboxOnStart() );
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)));
129 const int count = blogList.
count();
130 for(
int i=0; i < count; ++i) {
134 blogs->addAction( act );
136 connect( blogs, SIGNAL(triggered(
QAction*)),
this, SLOT(currentBlogChanged(
QAction*)) );
144 void MainWindow::setupStatusBar()
146 KPIM::ProgressStatusBarWidget * progressStatusBarWidget =
new KPIM::ProgressStatusBarWidget(statusBar(),
this, PimCommon::StorageServiceProgressManager::progressTypeValue());
147 statusBar()->addPermanentWidget( progressStatusBarWidget->littleProgress(), 0);
151 void MainWindow::initStorageService()
154 PimCommon::StorageServiceJobConfig *configJob = PimCommon::StorageServiceJobConfig::self();
155 configJob->registerConfigIf(settingsJob);
157 mStorageManager =
new PimCommon::StorageServiceManager(
this);
164 void MainWindow::slotUploadFileDone(
const QString &serviceName,
const QString &link)
166 Q_UNUSED(serviceName);
167 KMessageBox::information(
this, i18n(
"File uploaded. You can access to it at this url %1", link), i18n(
"Upload File"));
170 void MainWindow::slotUploadFileFailed(
const QString &serviceName,
const QString &filename)
172 Q_UNUSED(serviceName);
174 KMessageBox::error(
this, i18n(
"Error during upload."), i18n(
"Upload File"));
177 void MainWindow::slotActionFailed(
const QString &serviceName,
const QString &error)
179 KMessageBox::error(
this, i18n(
"%1 return an error '%2'", serviceName, error), i18n(
"Error"));
182 void MainWindow::slotCloseTabClicked()
184 const int currentIndex = tabPosts->currentIndex();
185 if (currentIndex != -1) {
186 slotRemovePostEntry(currentIndex);
195 const int count = tabPosts->count();
198 for(
int i =0; i<count; ++i) {
206 void MainWindow::setupActions()
208 KStandardAction::quit( qApp, SLOT(quit()), actionCollection() );
210 KStandardAction::preferences(
this, SLOT(optionsPreferences()), actionCollection() );
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()) );
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()) );
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()) );
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()) );
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()) );
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)) );
243 blogs =
new KSelectAction(
this );
244 actionCollection()->addAction(
QLatin1String(
"blogs_list" ), blogs );
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()) );
251 actionCollection()->addAction(
QLatin1String(
"upload_file"), mStorageManager->menuUploadServices(
this) );
252 actionCollection()->addAction(
QLatin1String(
"download_file"), mStorageManager->menuDownloadServices(
this) );
253 mStorageManager->setDefaultUploadFolder(Settings::self()->downloadDirectory());
256 void MainWindow::loadTempPosts()
260 const int count = tempList.
count();
264 for( ; it != endIt; ++it ) {
265 createPostEntry(it.
value(), (*it.
key()));
271 previousActivePostIndex = 0;
273 setCurrentBlog( activePost->currentPostBlogId() );
276 void MainWindow::setCurrentBlog(
int blog_id )
280 blogs->setCurrentItem( -1 );
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 ) );
295 void MainWindow::currentBlogChanged(
QAction *act )
298 if ( mCurrentBlogId == act->
data().
toInt() )
304 activePost->setCurrentPostBlogId( mCurrentBlogId );
308 blogs->setToolTip(
DBMan::self()->blogList().value( mCurrentBlogId )->blogUrl() );
312 activePost->setCurrentPostBlogId( mCurrentBlogId );
317 void MainWindow::slotCreateNewPost()
321 tabPosts->setCurrentWidget( createPostEntry( mCurrentBlogId,
BilboPost()) );
322 if ( mCurrentBlogId == -1 ) {
323 if ( !blogs->items().isEmpty() ) {
324 blogs->setCurrentItem( 0 );
325 currentBlogChanged( blogs->action( 0 ) );
328 if ( this->isVisible() == false ) {
333 void MainWindow::optionsPreferences()
340 if ( KConfigDialog::showDialog(
QLatin1String(
"settings") ) ) {
344 connect( dialog, SIGNAL(blogAdded(
BilboBlog)),
346 connect( dialog, SIGNAL(blogEdited(
BilboBlog)),
348 connect( dialog, SIGNAL(blogRemoved(
int)),
this, SLOT(slotBlogRemoved(
int)) );
351 connect( dialog, SIGNAL(dialogDestroyed(
QObject*)),
this, SLOT(slotDialogDestroyed(
QObject*)));
352 connect( dialog, SIGNAL(
settingsChanged()),
this, SLOT(slotSettingsChanged()));
356 void MainWindow::slotSettingsChanged()
359 mStorageManager->setDefaultUploadFolder(Settings::self()->downloadDirectory());
362 void MainWindow::slotDialogDestroyed(
QObject *win )
364 const QSize size = qobject_cast<
QWidget *>(win)->size();
367 Settings::setConfigWindowSize( size );
371 void MainWindow::addBlog()
374 addEditBlogWindow->setWindowModality( Qt::ApplicationModal );
375 addEditBlogWindow->setAttribute( Qt::WA_DeleteOnClose );
376 connect( addEditBlogWindow, SIGNAL(sigBlogAdded(
BilboBlog)),
378 addEditBlogWindow->show();
381 void MainWindow::slotBlogAdded(
const BilboBlog &blog )
386 blogs->addAction( act );
387 blogs->setCurrentAction( act );
388 currentBlogChanged( act );
393 void MainWindow::slotBlogEdited(
const BilboBlog &blog )
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() );
404 void MainWindow::slotBlogRemoved(
int blog_id )
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 ) );
413 blogs->removeAction( blogs->action( i ) );
414 if (blogs->currentItem() == -1)
421 void MainWindow::setupSystemTray()
423 if ( Settings::enableSysTrayIcon()) {
425 systemTray =
new KStatusNotifierItem(
this );
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);
432 }
else if ( systemTray ) {
433 systemTray->deleteLater();
438 void MainWindow::slotPostTitleChanged(
const QString& title )
441 tabPosts->setTabText( tabPosts->currentIndex(), title );
444 void MainWindow::slotToggleToolboxVisible(
bool isVisible )
449 void MainWindow::slotToolboxVisibilityChanged(
bool)
454 void MainWindow::slotActivePostChanged(
int index )
456 kDebug() <<
"new post index: " << index <<
"\tPrev Index: " << previousActivePostIndex;
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;
463 if (( prevActivePost != 0 ) && ( index != previousActivePostIndex ) ) {
466 prevActivePost->setCurrentPostBlogId( mCurrentBlogId );
470 activePostBlogId = activePost->currentPostBlogId();
471 if ( activePostBlogId != -1 && activePostBlogId != prevPostBlogId ) {
472 setCurrentBlog( activePostBlogId );
476 kError() <<
"ActivePost is NULL! tabPosts Current index is: " << tabPosts->currentIndex() ;
478 previousActivePostIndex = index;
481 void MainWindow::slotPublishPost()
484 if ( mCurrentBlogId == -1 ) {
485 KMessageBox::sorry(
this, i18n(
"You have to select a blog to publish this post to." ) );
488 if ( !activePost || tabPosts->currentIndex() == -1) {
489 KMessageBox::sorry(
this, i18n(
"There is no open post to submit." ) );
493 activePost->submitPost( mCurrentBlogId, *activePost->currentPost() );
496 void MainWindow::slotRemoveAllExclude(
int pos)
498 for(
int i = tabPosts->count()-1; i >=0; --i) {
510 tabPosts->removePage(widget);
513 if ( tabPosts->count() < 1 ) {
520 void MainWindow::slotRemovePostEntry(
int pos )
533 tabPosts->removePage(widget);
536 if ( tabPosts->count() < 1 ) {
543 void MainWindow::slotNewPostOpened(
BilboPost &newPost,
int blog_id )
546 QWidget * w = createPostEntry( blog_id, newPost );
547 tabPosts->setCurrentWidget( w );
550 void MainWindow::slotSavePostLocally()
553 if (activePost && (tabPosts->count() > 0)) {
555 activePost->saveLocally();
560 void MainWindow::slotError(
const QString & errorMessage )
562 kDebug() <<
"Error message: " << errorMessage;
563 KMessageBox::detailedError(
this, i18n(
"An error occurred in the last transaction." ), errorMessage );
564 statusBar()->clearMessage();
568 void MainWindow::writeConfigs()
572 Settings::setShowToolboxOnStart(
true );
574 Settings::setShowToolboxOnStart(
false );
580 switch ( event->
key() ) {
597 slotRemovePostEntry( tabPosts->currentIndex() );
600 KXmlGuiWindow::keyPressEvent( event );
606 void MainWindow::postManipulationDone(
bool isError,
const QString &customMessage )
610 KMessageBox::detailedError(
this, i18n(
"Submitting post failed"), customMessage);
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 ) );
627 void MainWindow::slotBusy(
bool isBusy)
629 kDebug()<<
"isBusy="<<isBusy<<
"\tbusyNumber="<<busyNumber;
631 this->setCursor(Qt::BusyCursor);
639 statusBar()->addPermanentWidget(progress);
643 if ( busyNumber < 1 ){
647 statusBar()->removeWidget(progress);
664 connect( temp, SIGNAL(postTitleChanged(
QString)),
665 this, SLOT(slotPostTitleChanged(
QString)) );
666 connect( temp, SIGNAL(postPublishingDone(
bool,
QString)),
667 this, SLOT(postManipulationDone(
bool,
QString)) );
669 connect( temp, SIGNAL(showStatusMessage(
QString,
bool)),
670 this, SLOT(slotShowStatusMessage(
QString,
bool)));
672 connect( temp, SIGNAL(sigBusy(
bool)),
this, SLOT(slotBusy(
bool)) );
674 tabPosts->addTab( temp, post.title() );
678 void MainWindow::slotShowStatusMessage(
const QString &message,
bool isPermanent)
680 statusBar()->showMessage(message, (isPermanent ? 0 :
TIMEOUT));
683 void MainWindow::uploadMediaObject()
686 connect(uploadDlg, SIGNAL(sigBusy(
bool)), SLOT(slotBusy(
bool)));
687 if (mCurrentBlogId == -1)
688 uploadDlg->
init( 0 );
693 void MainWindow::slotOpenCurrentBlogInBrowser()
695 if (mCurrentBlogId > -1) {
696 KUrl url(
DBMan::self()->blog( mCurrentBlogId )->blogUrl() );
698 KToolInvocation::invokeBrowser(url.url());
700 KMessageBox::sorry(
this, i18n(
"Cannot find current blog URL."));
void setMaximum(int maximum)
Qt::KeyboardModifiers modifiers() const
QList< T > values() const
QString lastErrorText() const
const_iterator constBegin() const
const T & at(int i) const
void closeEvent(QCloseEvent *event)
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 :)
void setMinimum(int minimum)
int count(const T &value) const
int toInt(bool *ok) const
int __currentBlogId
Global variables.
void setObjectName(const QString &name)
const_iterator constEnd() const
Post Entry Widget contains Editor, and Title box.
void setData(const QVariant &userData)
void keyPressEvent(QKeyEvent *event)
const QMap< int, BilboBlog * > & blogList() const
bool removeTempEntry(const BilboPost &post)
QMap< BilboPost *, int > listTempPosts()
Returns list of temporary posts, e.g.
const Key key(const T &value) const
int currentPostBlogId() const
BilboPost * currentPost()
void setCurrentPost(const BilboPost &post)
int count(const Key &key) const
const T value(const Key &key) const
void setCurrentPostBlogId(int blog_id)