40 #include "ui_advancedsettingsbase.h"
41 #include "ui_settingsbase.h"
42 #include "ui_editorsettingsbase.h"
44 #include <ktabwidget.h>
45 #include <KStatusNotifierItem>
46 #include <kstatusbar.h>
47 #include <KToggleAction>
48 #include <kactioncollection.h>
49 #include <kconfigdialog.h>
51 #include <kmessagebox.h>
52 #include <KDE/KLocale>
53 #include <KSelectAction>
54 #include <kimagefilepreview.h>
55 #include <KToolInvocation>
60 #include <QDockWidget>
61 #include <QProgressBar>
71 previousActivePostIndex(-1),
76 setWindowTitle( i18n(
"Blogilo") );
79 setCentralWidget( tabPosts );
81 connect(tabPosts,SIGNAL(closeTabClicked()),SLOT(slotCloseTabClicked()));
83 connect(tabPosts,SIGNAL(tabRemoveAllExclude(
int)),
this, SLOT(slotRemoveAllExclude(
int)));
86 toolboxDock =
new QDockWidget( i18n(
"Toolbox" ),
this );
87 toolboxDock->setAllowedAreas( Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea );
88 toolboxDock->setFeatures( QDockWidget::AllDockWidgetFeatures );
89 toolboxDock->setWidget( toolbox );
91 toolboxDock->setObjectName( QLatin1String(
"dock_toolbox") );
92 toolbox->setObjectName( QLatin1String(
"toolbox") );
94 this->addDockWidget( Qt::RightDockWidgetArea, toolboxDock );
116 connect( toolbox, SIGNAL(sigError(QString)),
this, SLOT(
slotError(QString)) );
117 connect( toolbox, SIGNAL(sigBusy(
bool)),
this, SLOT(slotBusy(
bool)));
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 );
127 connect( blogs, SIGNAL(triggered(QAction*)),
this, SLOT(currentBlogChanged(QAction*)) );
135 void MainWindow::slotCloseTabClicked()
137 const int currentIndex = tabPosts->currentIndex();
138 if (currentIndex != -1) {
148 const int count = tabPosts->count();
151 for(
int i =0; i<count; ++i) {
159 void MainWindow::setupActions()
161 KStandardAction::quit( qApp, SLOT(quit()), actionCollection() );
163 KStandardAction::preferences(
this, SLOT(optionsPreferences()), actionCollection() );
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 );
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()) );
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()) );
179 KAction *actUpload =
new KAction( KIcon( QLatin1String(
"upload-media") ), i18n(
"Upload Media..." ),
this );
180 actionCollection()->addAction( QLatin1String(
"upload_media" ), actUpload );
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 );
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)),
193 connect( toolboxDock, SIGNAL(visibilityChanged(
bool)),
196 blogs =
new KSelectAction(
this );
197 actionCollection()->addAction( QLatin1String(
"blogs_list" ), blogs );
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"));
209 const int count = tempList.count();
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()));
220 previousActivePostIndex = 0;
222 setCurrentBlog( activePost->currentPostBlogId() );
225 void MainWindow::setCurrentBlog(
int blog_id )
229 blogs->setCurrentItem( -1 );
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 ) );
244 void MainWindow::currentBlogChanged( QAction *act )
247 if ( mCurrentBlogId == act->data().toInt() )
249 mCurrentBlogId = act->data().toInt();
253 activePost->setCurrentPostBlogId( mCurrentBlogId );
257 blogs->setToolTip(
DBMan::self()->blogList().value( mCurrentBlogId )->blogUrl() );
261 activePost->setCurrentPostBlogId( mCurrentBlogId );
270 tabPosts->setCurrentWidget( createPostEntry( mCurrentBlogId,
BilboPost()) );
271 if ( mCurrentBlogId == -1 ) {
272 if ( !blogs->items().isEmpty() ) {
273 blogs->setCurrentItem( 0 );
274 currentBlogChanged( blogs->action( 0 ) );
277 if ( this->isVisible() == false ) {
282 void MainWindow::optionsPreferences()
289 if ( KConfigDialog::showDialog( QLatin1String(
"settings") ) ) {
292 KConfigDialog *dialog =
new KConfigDialog(
this, QLatin1String(
"settings"),
Settings::self() );
294 generalSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
295 Ui::SettingsBase ui_prefs_base;
296 Ui::EditorSettingsBase ui_editorsettings_base;
297 ui_prefs_base.setupUi( generalSettingsDlg );
299 blogSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
300 connect( blogSettingsDlg, SIGNAL(blogAdded(
BilboBlog)),
302 connect( blogSettingsDlg, SIGNAL(blogEdited(
BilboBlog)),
304 connect( blogSettingsDlg, SIGNAL(blogRemoved(
int)),
this, SLOT(slotBlogRemoved(
int)) );
306 editorSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
307 ui_editorsettings_base.setupUi( editorSettingsDlg );
309 advancedSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
310 Ui::AdvancedSettingsBase ui_advancedsettings_base;
311 ui_advancedsettings_base.setupUi( advancedSettingsDlg );
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"));
319 connect( dialog, SIGNAL(destroyed(
QObject*)),
this, SLOT(slotDialogDestroyed(
QObject*)));
320 dialog->setAttribute( Qt::WA_DeleteOnClose );
330 void MainWindow::slotDialogDestroyed(
QObject *win )
332 const QSize size = qobject_cast<
QWidget *>(win)->size();
333 const QString name = win->objectName();
334 if (name == QLatin1String(
"settings")) {
342 addEditBlogWindow->setWindowModality( Qt::ApplicationModal );
343 addEditBlogWindow->setAttribute( Qt::WA_DeleteOnClose );
344 connect( addEditBlogWindow, SIGNAL(sigBlogAdded(
BilboBlog)),
346 addEditBlogWindow->show();
349 void MainWindow::slotBlogAdded(
const BilboBlog &blog )
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 );
361 void MainWindow::slotBlogEdited(
const BilboBlog &blog )
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() );
372 void MainWindow::slotBlogRemoved(
int blog_id )
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 ) );
381 blogs->removeAction( blogs->action( i ) );
382 if (blogs->currentItem() == -1)
389 void MainWindow::setupSystemTray()
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);
400 }
else if ( systemTray ) {
401 systemTray->deleteLater();
409 tabPosts->setTabText( tabPosts->currentIndex(), title );
414 toolboxDock->setVisible( isVisible );
419 actionCollection()->action(QLatin1String(
"toggle_toolbox"))->setChecked( toolboxDock->isVisibleTo(
this) );
424 kDebug() <<
"new post index: " << index <<
"\tPrev Index: " << previousActivePostIndex;
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;
431 if (( prevActivePost != 0 ) && ( index != previousActivePostIndex ) ) {
434 prevActivePost->setCurrentPostBlogId( mCurrentBlogId );
438 activePostBlogId = activePost->currentPostBlogId();
439 if ( activePostBlogId != -1 && activePostBlogId != prevPostBlogId ) {
440 setCurrentBlog( activePostBlogId );
444 kError() <<
"ActivePost is NULL! tabPosts Current index is: " << tabPosts->currentIndex() ;
446 previousActivePostIndex = index;
452 if ( mCurrentBlogId == -1 ) {
453 KMessageBox::sorry(
this, i18n(
"You have to select a blog to publish this post to." ) );
456 if ( !activePost || tabPosts->currentIndex() == -1) {
457 KMessageBox::sorry(
this, i18n(
"There is no open post to submit." ) );
461 activePost->submitPost( mCurrentBlogId, *activePost->currentPost() );
464 void MainWindow::slotRemoveAllExclude(
int pos)
466 for(
int i = tabPosts->count()-1; i >=0; --i) {
478 tabPosts->removePage(widget);
481 if ( tabPosts->count() < 1 ) {
501 tabPosts->removePage(widget);
504 if ( tabPosts->count() < 1 ) {
514 QWidget * w = createPostEntry( blog_id, newPost );
515 tabPosts->setCurrentWidget( w );
521 if (activePost && (tabPosts->count() > 0)) {
523 activePost->saveLocally();
530 kDebug() <<
"Error message: " << errorMessage;
531 KMessageBox::detailedError(
this, i18n(
"An error occurred in the last transaction." ), errorMessage );
532 statusBar()->clearMessage();
536 void MainWindow::writeConfigs()
539 if ( toolboxDock->isVisible() )
547 if ( event->modifiers() == Qt::CTRL ) {
548 switch ( event->key() ) {
568 KXmlGuiWindow::keyPressEvent( event );
574 void MainWindow::postManipulationDone(
bool isError,
const QString &customMessage )
578 KMessageBox::detailedError(
this, i18n(
"Submitting post failed"), customMessage);
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 ) {
592 toolbox->unsetCursor();
595 void MainWindow::slotBusy(
bool isBusy)
597 kDebug()<<
"isBusy="<<isBusy<<
"\tbusyNumber="<<busyNumber;
599 this->setCursor(Qt::BusyCursor);
600 toolbox->setCursor( Qt::BusyCursor );
603 progress =
new QProgressBar(statusBar());
604 progress->setMinimum( 0 );
605 progress->setMaximum( 0 );
606 progress->setFixedSize(250, 17);
607 statusBar()->addPermanentWidget(progress);
611 if ( busyNumber < 1 ){
613 toolbox->unsetCursor();
615 statusBar()->removeWidget(progress);
616 progress->deleteLater();
628 temp->setAttribute( Qt::WA_DeleteOnClose );
632 connect( temp, SIGNAL(postTitleChanged(QString)),
634 connect( temp, SIGNAL(postPublishingDone(
bool,QString)),
635 this, SLOT(postManipulationDone(
bool,QString)) );
637 connect( temp, SIGNAL(showStatusMessage(QString,
bool)),
638 this, SLOT(slotShowStatusMessage(QString,
bool)));
640 connect( temp, SIGNAL(sigBusy(
bool)),
this, SLOT(slotBusy(
bool)) );
642 tabPosts->addTab( temp, post.title() );
646 void MainWindow::slotShowStatusMessage(
const QString &message,
bool isPermanent)
648 statusBar()->showMessage(message, (isPermanent ? 0 :
TIMEOUT));
654 connect(uploadDlg, SIGNAL(sigBusy(
bool)), SLOT(slotBusy(
bool)));
655 if (mCurrentBlogId == -1)
656 uploadDlg->
init( 0 );
663 if (mCurrentBlogId > -1) {
664 KUrl url(
DBMan::self()->blog( mCurrentBlogId )->blogUrl() );
666 KToolInvocation::invokeBrowser(url.url());
668 KMessageBox::sorry(
this, i18n(
"Cannot find current blog URL."));
674 #include "mainwindow.moc"
void slotError(const QString &errorMessage)
void slotSettingsChanged()
void slotPostTitleChanged(const QString &title)
static bool showToolboxOnStart()
Get showToolboxOnStart.
void slotNewPostOpened(BilboPost &newPost, int blog_id)
QString lastErrorText() const
static bool enableSysTrayIcon()
Get enableSysTrayIcon.
void slotToolboxVisibilityChanged(bool isVisible)
static void setShowToolboxOnStart(bool v)
Set showToolboxOnStart.
static void setConfigWindowSize(const QSize &v)
Set configWindowSize.
int saveTempEntry(const BilboPost &post, int blog_id)
static QSize configWindowSize()
Get configWindowSize.
static DBMan * self()
Retrieve the instance of DataBase Manager.
Definition of a blog post! it's implemented to decrease dependency to KBlog :)
int __currentBlogId
Global variables.
Post Entry Widget contains Editor, and Title box.
void slotActivePostChanged(int tabIndex)
void slotRemovePostEntry(int post)
Remove widget at position pos from main tab wigdet.
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.
void slotOpenCurrentBlogInBrowser()
void slotToggleToolboxVisible(bool isVisible)
int currentPostBlogId() const
void loadTempPosts()
To open temporary posts and that posts are open at previous quit.
BilboPost * currentPost()
void setCurrentPost(const BilboPost &post)
void slotSavePostLocally()
void setCurrentPostBlogId(int blog_id)