Page MenuHomePhorge

No OneTemporary

diff --git a/blogilo/src/mainwindow.cpp b/blogilo/src/mainwindow.cpp
index 732dc6db41..6abb8e91c4 100644
--- a/blogilo/src/mainwindow.cpp
+++ b/blogilo/src/mainwindow.cpp
@@ -1,672 +1,674 @@
/*
This file is part of Blogilo, A KDE Blogging Client
Copyright (C) 2008-2010 Mehrdad Momeny <mehrdad.momeny@gmail.com>
Copyright (C) 2008-2010 Golnaz Nilieh <g382nilieh@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/
*/
#include "mainwindow.h"
#include "global.h"
#include "dbman.h"
#include "toolbox.h"
#include "postentry.h"
#include "addeditblog.h"
#include "backend.h"
#include "bilbomedia.h"
#include "settings.h"
#include "bilboblog.h"
// #include "composer/multilinetextedit.h"
#include "blogsettings.h"
// #include "htmleditor.h"
#include "ui_advancedsettingsbase.h"
#include "ui_settingsbase.h"
#include "ui_editorsettingsbase.h"
#include <kdeversion.h>
#include <ktabwidget.h>
#include <KStatusNotifierItem>
#include <kstatusbar.h>
#include <KToggleAction>
#include <kactioncollection.h>
#include <kconfigdialog.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <KDE/KLocale>
#include <QDir>
#include <QDockWidget>
#include <QProgressBar>
#include <KSelectAction>
#include <kimagefilepreview.h>
#include "uploadmediadialog.h"
#include <QTimer>
#include <KToolInvocation>
#include <KMenu>
#define TIMEOUT 5000
MainWindow::MainWindow()
: KXmlGuiWindow(), activePost(0), systemTray(0), previousActivePostIndex(-1),
busyNumber(0), progress(0), mCurrentBlogId(__currentBlogId)
{
kDebug();
setWindowTitle( i18n("Blogilo") );
tabPosts = new KTabWidget( this );
tabPosts->setElideMode( Qt::ElideRight );
tabPosts->setTabsClosable( true );
// #if KDE_IS_VERSION( 4, 5, 80 )
/// does not build with KDE 4.5.80: Compile Error: ‘QTabBar* QTabWidget::tabBar() const’ is protected
// tabPosts->tabBar()->setSelectionBehaviorOnRemove( QTabBar::SelectPreviousTab );
// #else
tabPosts->setTabCloseActivatePrevious( true );
// #endif
tabPosts->setDocumentMode(true);
connect( tabPosts, SIGNAL( tabCloseRequested( int ) ), this, SLOT( slotRemovePostEntry( int ) ) );
setCentralWidget( tabPosts );
// this->setDockOptions( QMainWindow::ForceTabbedDocks);
toolbox = new Toolbox( this );
toolboxDock = new QDockWidget( i18n( "Toolbox" ), this );
toolboxDock->setAllowedAreas( Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea );
toolboxDock->setFeatures( QDockWidget::AllDockWidgetFeatures );
toolboxDock->setObjectName( "dock_toolbox" );
toolbox->setObjectName( "toolbox" );
toolboxDock->setWidget( toolbox );
this->addDockWidget( Qt::RightDockWidgetArea, toolboxDock );
//btnRemovePost = new QToolButton( tabPosts );
//btnRemovePost->setIcon( KIcon( "tab-close" ) );
//btnRemovePost->setToolTip( i18n( "Close tab" ) );
//tabPosts->setCornerWidget( btnRemovePost, Qt::TopRightCorner );
//connect( btnRemovePost, SIGNAL( clicked( bool ) ), this, SLOT( slotRemovePostEntry() ) );
// then, setup our actions
setupActions();
// add a status bar
statusBar()->show();
// toolbox->show();
// a call to KXmlGuiWindow::setupGUI() populates the GUI
// with actions, using KXMLGUI.
// It also applies the saved mainwindow settings, if any, and ask the
// mainwindow to automatically save settings if changed: window size,
// toolbar position, icon size, etc.
setupGUI();
toolbox->setVisible( Settings::showToolboxOnStart() );
actionCollection()->action("toggle_toolbox")->setChecked( Settings::showToolboxOnStart() );
setupSystemTray();
connect( tabPosts, SIGNAL( currentChanged( int ) ), this, SLOT( slotActivePostChanged( int ) ) );
connect( toolbox, SIGNAL( sigEntrySelected( BilboPost &, int ) ), this, SLOT( slotNewPostOpened( BilboPost&, int ) ) );
// connect( toolbox, SIGNAL( sigCurrentBlogChanged( int ) ), this, SLOT( slotCurrentBlogChanged( int ) ) );
connect( toolbox, SIGNAL( sigError( const QString& ) ), this, SLOT( slotError( const QString& ) ) );
connect( toolbox, SIGNAL( sigBusy(bool) ), this, SLOT( slotBusy(bool) ));
QList<BilboBlog*> blogList = DBMan::self()->blogList().values();
int count = blogList.count();
for(int i=0; i < count; ++i) {
QAction *act = new QAction( blogList[i]->title(), blogs );
act->setCheckable( true );
act->setData( blogList[i]->id() );
blogs->addAction( act );
}
connect( blogs, SIGNAL(triggered( QAction* )), this, SLOT(currentBlogChanged(QAction*)) );
QTimer::singleShot( 0, this, SLOT( loadTempPosts() ) );
}
MainWindow::~MainWindow()
{
kDebug();
}
bool MainWindow::queryExit()
{
kDebug();
writeConfigs();
if( !DBMan::self()->clearTempEntries() )
kDebug()<<"Could not erase temp_post table: "<< DBMan::self()->lastErrorText();
int count = tabPosts->count();
if(count > 0) {
toolbox->getFieldsValue(activePost->currentPost());
for(int i =0; i<count; ++i) {
PostEntry* pst = qobject_cast<PostEntry*>(tabPosts->widget(i));
DBMan::self()->saveTempEntry(*pst->currentPost(), pst->currentPostBlogId());
}
}
return true;
}
void MainWindow::setupActions()
{
KStandardAction::quit( qApp, SLOT( quit() ), actionCollection() );
KStandardAction::preferences( this, SLOT( optionsPreferences() ), actionCollection() );
// custom menu and menu item
KAction *actNewPost = new KAction( KIcon( "document-new" ), i18n( "New Post" ), this );
actionCollection()->addAction( QLatin1String( "new_post" ), actNewPost );
actNewPost->setShortcut( Qt::CTRL + Qt::Key_N );
connect( actNewPost, SIGNAL( triggered( bool ) ), this, SLOT( slotCreateNewPost() ) );
KAction *actAddBlog = new KAction( KIcon( "list-add" ), i18n( "Add Blog..." ), this );
actionCollection()->addAction( QLatin1String( "add_blog" ), actAddBlog );
connect( actAddBlog, SIGNAL( triggered( bool ) ), this, SLOT( addBlog() ) );
KAction *actPublish = new KAction( KIcon( "arrow-up" ), i18n( "Submit..." ), this );
actionCollection()->addAction( QLatin1String( "publish_post" ), actPublish );
connect( actPublish, SIGNAL( triggered( bool ) ), this, SLOT( slotPublishPost() ) );
KAction *actUpload = new KAction( KIcon( "upload-media" ), i18n( "Upload Media..." ), this );
actionCollection()->addAction( QLatin1String( "upload_media" ), actUpload );
connect( actUpload, SIGNAL( triggered( bool ) ), this, SLOT( uploadMediaObject() ) );
KAction *actSaveLocally = new KAction( KIcon( "document-save" ), i18n( "Save Locally" ), this );
actionCollection()->addAction( QLatin1String( "save_locally" ), actSaveLocally );
actSaveLocally->setShortcut( Qt::CTRL + Qt::Key_S );
connect( actSaveLocally, SIGNAL( triggered( bool ) ), this, SLOT( slotSavePostLocally() ) );
KToggleAction *actToggleToolboxVisible = new KToggleAction( i18n( "Show Toolbox" ), this );
actionCollection()->addAction( QLatin1String( "toggle_toolbox" ), actToggleToolboxVisible );
actToggleToolboxVisible->setShortcut( Qt::CTRL + Qt::Key_T );
connect( actToggleToolboxVisible, SIGNAL( toggled( bool ) ),
this, SLOT( slotToggleToolboxVisible( bool ) ) );
connect( toolboxDock, SIGNAL(visibilityChanged(bool)),
this, SLOT( slotToolboxVisibilityChanged(bool) ) );
blogs = new KSelectAction( this );
actionCollection()->addAction( QLatin1String( "blogs_list" ), blogs );
KAction *actOpenBlog = new KAction(KIcon("applications-internet"), i18n("Open in browser"), this);
actionCollection()->addAction( QLatin1String("open_blog_in_browser"), actOpenBlog);
actOpenBlog->setToolTip(i18n("Open current blog in browser"));
connect( actOpenBlog, SIGNAL(triggered(bool)), this, SLOT(slotOpenCurrentBlogInBrowser()) );
}
void MainWindow::loadTempPosts()
{
kDebug();
QMap<BilboPost*, int> tempList = DBMan::self()->listTempPosts();
int count = tempList.count();
if( count > 0 ){
QMap<BilboPost*, int>::ConstIterator it = tempList.constBegin();
QMap<BilboPost*, int>::ConstIterator endIt = tempList.constEnd();
for( ; it != endIt; ++it ) {
createPostEntry(it.value(), (*it.key()));
}
} else {
slotCreateNewPost();
}
// activePost = qobject_cast<PostEntry*>( tabPosts->currentWidget() );
previousActivePostIndex = 0;
if( activePost )
setCurrentBlog( activePost->currentPostBlogId() );
}
void MainWindow::setCurrentBlog( int blog_id )
{
kDebug()<<blog_id;
if(blog_id == -1) {
blogs->setCurrentItem( -1 );
toolbox->setCurrentBlogId( blog_id );
// actionCollection()->action("publish_post")->setEnabled( false );
return;
}
int count = blogs->items().count();
for (int i=0; i<count; ++i) {
if( blogs->action(i)->data().toInt() == blog_id ) {
blogs->setCurrentItem( i );
currentBlogChanged( blogs->action( i ) );
break;
}
}
}
void MainWindow::currentBlogChanged( QAction *act )
{
if( act ) {
if( mCurrentBlogId == act->data().toInt() )
return;
mCurrentBlogId = act->data().toInt();
// __currentBlogId = mCurrentBlogId;
if( activePost ) {
// actionCollection()->action("publish_post")->setEnabled( true );
activePost->setCurrentPostBlogId( mCurrentBlogId );
} else {
// actionCollection()->action("publish_post")->setEnabled( false );
}
blogs->setToolTip( DBMan::self()->blogList().value( mCurrentBlogId )->blogUrl() );
} else {
mCurrentBlogId = -1;
if( activePost )
activePost->setCurrentPostBlogId( mCurrentBlogId );
}
toolbox->setCurrentBlogId( mCurrentBlogId );
}
void MainWindow::slotCreateNewPost()
{
kDebug();
tabPosts->setCurrentWidget( createPostEntry( mCurrentBlogId, BilboPost()) );
if( mCurrentBlogId == -1 ) {
if( blogs->items().count() > 0 ) {
blogs->setCurrentItem( 0 );
currentBlogChanged( blogs->action( 0 ) );
}
}
if ( this->isVisible() == false ) {
this->show();
}
}
void MainWindow::optionsPreferences()
{
// The preference dialog is derived from prefs_base.ui
//
// compare the names of the widgets in the .ui file
// to the names of the variables in the .kcfg file
//avoid having 2 dialogs shown
if ( KConfigDialog::showDialog( "settings" ) ) {
return;
}
KConfigDialog *dialog = new KConfigDialog( this, "settings", Settings::self() );
QWidget *generalSettingsDlg = new QWidget;
generalSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
Ui::SettingsBase ui_prefs_base;
Ui::EditorSettingsBase ui_editorsettings_base;
ui_prefs_base.setupUi( generalSettingsDlg );
BlogSettings *blogSettingsDlg = new BlogSettings;
blogSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
connect( blogSettingsDlg, SIGNAL(blogAdded(const BilboBlog &)),
this, SLOT(slotBlogAdded(const BilboBlog &)) );
connect( blogSettingsDlg, SIGNAL(blogEdited(const BilboBlog &)),
this, SLOT(slotBlogEdited(const BilboBlog &)) );
connect( blogSettingsDlg, SIGNAL(blogRemoved(int)), this, SLOT(slotBlogRemoved(int)) );
QWidget *editorSettingsDlg = new QWidget;
editorSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
ui_editorsettings_base.setupUi( editorSettingsDlg );
QWidget *advancedSettingsDlg = new QWidget;
advancedSettingsDlg->setAttribute( Qt::WA_DeleteOnClose );
Ui::AdvancedSettingsBase ui_advancedsettings_base;
ui_advancedsettings_base.setupUi( advancedSettingsDlg );
// QWidget *htmlEditorSettings = HtmlEditor::self()->configPage( 0, dialog );
// dialog->addPage( htmlEditorSettings, i18n( "HTML Editor" ), "configure" );
dialog->addPage( generalSettingsDlg, i18nc( "Configure Page", "General" ), "configure" );
dialog->addPage( blogSettingsDlg, i18nc( "Configure Page", "Blogs" ), "document-properties");
dialog->addPage( editorSettingsDlg, i18nc( "Configure Page", "Editor" ), "accessories-text-editor" );
dialog->addPage( advancedSettingsDlg, i18nc( "Configure Page", "Advanced" ), "applications-utilities");
connect( dialog, SIGNAL( settingsChanged( const QString& ) ), this, SIGNAL( settingsChanged() ) );
connect( dialog, SIGNAL(settingsChanged(const QString& )), this, SLOT(slotSettingsChanged()) );
connect( dialog, SIGNAL(destroyed(QObject*)), this, SLOT(slotDialogDestroyed(QObject*)));
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->resize( Settings::configWindowSize() );
dialog->show();
}
void MainWindow::slotSettingsChanged()
{
setupSystemTray();
}
void MainWindow::slotDialogDestroyed( QObject *win )
{
QSize size = qobject_cast<QWidget *>(win)->size();
QString name = win->objectName();
if(name == "settings") {
Settings::setConfigWindowSize( size );
}
}
void MainWindow::addBlog()
{
AddEditBlog *addEditBlogWindow = new AddEditBlog( -1, this );
addEditBlogWindow->setWindowModality( Qt::ApplicationModal );
addEditBlogWindow->setAttribute( Qt::WA_DeleteOnClose );
connect( addEditBlogWindow, SIGNAL( sigBlogAdded( const BilboBlog& ) ),
this, SLOT( slotBlogAdded( const BilboBlog& ) ) );
addEditBlogWindow->show();
}
void MainWindow::slotBlogAdded( const BilboBlog &blog )
{
QAction *act = new QAction( blog.title(), blogs );
act->setCheckable( true );
act->setData( blog.id() );
blogs->addAction( act );
blogs->setCurrentAction( act );
currentBlogChanged( act );
toolbox->slotReloadCategoryList();
toolbox->slotUpdateEntries( 20 );
}
void MainWindow::slotBlogEdited( const BilboBlog &blog )
{
int count = blogs->actions().count();
for(int i=0; i< count; ++i){
if( blogs->action( i )->data().toInt() == blog.id() ) {
blogs->action( i )->setText( blog.title() );
break;
}
}
}
void MainWindow::slotBlogRemoved( int blog_id )
{
int count = blogs->actions().count();
for(int i=0; i< count; ++i){
if( blogs->action( i )->data().toInt() == blog_id ) {
if( blogs->currentItem() == i ) {
blogs->setCurrentItem( i-1 );
currentBlogChanged( blogs->action( i-1 ) );
}
blogs->removeAction( blogs->action( i ) );
if(blogs->currentItem() == -1)
toolbox->clearFields();
break;
}
}
}
void MainWindow::setupSystemTray()
{
if( Settings::enableSysTrayIcon()) {
if ( !systemTray ) {
systemTray = new KStatusNotifierItem( this );
systemTray->setIconByName("blogilo");
systemTray->setToolTip( "blogilo", i18n("Blogilo"), i18n("A KDE Blogging Client") );
systemTray->contextMenu()->addAction( actionCollection()->action("new_post") );
systemTray->setCategory(KStatusNotifierItem::ApplicationStatus);
systemTray->setStatus(KStatusNotifierItem::Active);
}
} else if( systemTray ) {
systemTray->deleteLater();
systemTray = 0;
}
}
void MainWindow::slotUploadAllChanges()
{
kDebug();
}
void MainWindow::slotPostTitleChanged( const QString& title )
{
// kDebug();
tabPosts->setTabText( tabPosts->currentIndex(), title );
}
void MainWindow::slotToggleToolboxVisible( bool isVisible )
{
toolboxDock->setVisible( isVisible );
}
void MainWindow::slotToolboxVisibilityChanged(bool)
{
actionCollection()->action(QLatin1String("toggle_toolbox"))->setChecked( toolboxDock->isVisibleTo(this) );
}
void MainWindow::slotActivePostChanged( int index )
{
kDebug() << "new post index: " << index << "\tPrev Index: " << previousActivePostIndex;
activePost = qobject_cast<PostEntry*>( tabPosts->widget( index ) );
PostEntry *prevActivePost = qobject_cast<PostEntry*>( tabPosts->widget( previousActivePostIndex ) );
int activePostBlogId = -1;
int prevPostBlogId = -1;
if (( prevActivePost != 0 ) && ( index != previousActivePostIndex ) ) {
prevPostBlogId = prevActivePost->currentPostBlogId();
toolbox->getFieldsValue( prevActivePost->currentPost() );
prevActivePost->setCurrentPostBlogId( mCurrentBlogId );
}
if ( index >= 0 ) {
activePostBlogId = activePost->currentPostBlogId();
if ( activePostBlogId != -1 && activePostBlogId != prevPostBlogId ) {
setCurrentBlog( activePostBlogId );
}
toolbox->setFieldsValue( activePost->currentPost() );
} else {
kError() << "ActivePost is NULL! tabPosts Current index is: " << tabPosts->currentIndex() ;
}
previousActivePostIndex = index;
}
void MainWindow::slotPublishPost()
{
kDebug();
if ( mCurrentBlogId == -1 ) {
KMessageBox::sorry( this, i18n( "You have to select a blog to publish this post to." ) );
kDebug() << "Blog id not sets correctly.";
return;
}
if( !activePost || tabPosts->currentIndex() == -1) {
KMessageBox::sorry( this, i18n( "There is no open post to submit." ) );
kDebug() << "There isn't any post";
return;
}
toolbox->getFieldsValue( activePost->currentPost() );
// post.setPrivate( false );
activePost->submitPost( mCurrentBlogId, *activePost->currentPost() );
}
void MainWindow::slotRemovePostEntry( int pos )
{
kDebug();
PostEntry *widget = qobject_cast<PostEntry*>( tabPosts->widget( pos ) );
if( !widget ) {
if( activePost )
widget = activePost;
else
return;
}
DBMan::self()->removeTempEntry( *widget->currentPost() );
tabPosts->removePage(widget);
widget->close();
// if(tabPosts->count() == 1)
// tabPosts->setTabBarHidden(true);
// else
// tabPosts->setTabBarHidden(false);
// if( tabPosts->count() == 0 ){
// slotCreateNewPost();
// previousActivePostIndex = 0;
// }
if( tabPosts->count() < 1 ) {
activePost = 0;
toolbox->resetFields();
// actionCollection()->action("publish_post")->setEnabled( false );
}
}
void MainWindow::slotNewPostOpened( BilboPost &newPost, int blog_id )
{
kDebug();
QWidget * w = createPostEntry( blog_id, newPost );
tabPosts->setCurrentWidget( w );
}
void MainWindow::slotSavePostLocally()
{
kDebug();
if(activePost && tabPosts->count() > 0) {
toolbox->getFieldsValue(activePost->currentPost());
activePost->saveLocally();
toolbox->reloadLocalPosts();
}
}
void MainWindow::slotError( const QString & errorMessage )
{
kDebug() << "Error message: " << errorMessage;
KMessageBox::detailedError( this, i18n( "An error occurred in the last transaction." ), errorMessage );
statusBar()->clearMessage();
slotBusy(false);
}
void MainWindow::writeConfigs()
{
kDebug();
if ( toolboxDock->isVisible() )
Settings::setShowToolboxOnStart( true );
else
Settings::setShowToolboxOnStart( false );
}
void MainWindow::keyPressEvent( QKeyEvent * event )
{
if ( event->modifiers() == Qt::CTRL ) {
switch ( event->key() ) {
case Qt::Key_1:
toolbox->setCurrentPage( 0 );
break;
case Qt::Key_2:
toolbox->setCurrentPage( 1 );
break;
case Qt::Key_3:
toolbox->setCurrentPage( 2 );
break;
case Qt::Key_4:
toolbox->setCurrentPage( 3 );
break;
case Qt::Key_5:
toolbox->setCurrentPage( 4 );
break;
case Qt::Key_W:
slotRemovePostEntry( tabPosts->currentIndex() );
break;
default:
KXmlGuiWindow::keyPressEvent( event );
break;
}
}
}
void MainWindow::postManipulationDone( bool isError, const QString &customMessage )
{
kDebug();
if(isError){
KMessageBox::detailedError(this, i18n("Submitting post failed"), customMessage);
} else {
PostEntry *entry = qobject_cast<PostEntry*>(sender());
- if(entry && KMessageBox::questionYesNo(this, i18n("%1\nDo you want to keep the post open?", customMessage),
+ if(entry){
+ if (KMessageBox::questionYesNo(this, i18n("%1\nDo you want to keep the post open?", customMessage),
QString(), KStandardGuiItem::yes(), KStandardGuiItem::no(), "KeepPostOpen") == KMessageBox::No ) {
slotRemovePostEntry( tabPosts->indexOf( entry ) );
- } else {
+ } else {
toolbox->setFieldsValue(entry->currentPost());
+ }
}
toolbox->slotLoadEntriesFromDB( mCurrentBlogId );
}
this->unsetCursor();
toolbox->unsetCursor();
}
void MainWindow::slotBusy(bool isBusy)
{
kDebug()<<"isBusy="<<isBusy<<"\tbusyNumber="<<busyNumber;
if(isBusy){
this->setCursor(Qt::BusyCursor);
toolbox->setCursor( Qt::BusyCursor );
++busyNumber;
if(!progress){
progress = new QProgressBar(statusBar());
progress->setMinimum( 0 );
progress->setMaximum( 0 );
progress->setFixedSize(250, 17);
statusBar()->addPermanentWidget(progress);
}
} else {
--busyNumber;
if( busyNumber < 1 ){
this->unsetCursor();
toolbox->unsetCursor();
if(progress){
statusBar()->removeWidget(progress);
progress->deleteLater();
progress = 0;
}
// busyNumber = 0;
}
}
}
QWidget* MainWindow::createPostEntry(int blog_id, const BilboPost& post)
{
kDebug();
PostEntry *temp = new PostEntry( this );
temp->setAttribute( Qt::WA_DeleteOnClose );
temp->setCurrentPost(post);
temp->setCurrentPostBlogId( blog_id );
connect( temp, SIGNAL( postTitleChanged( const QString& ) ),
this, SLOT( slotPostTitleChanged( const QString& ) ) );
connect( temp, SIGNAL( postPublishingDone( bool, const QString& ) ),
this, SLOT( postManipulationDone( bool, const QString& ) ) );
connect( this, SIGNAL( settingsChanged() ), temp, SLOT( settingsChanged() ));
connect( temp, SIGNAL( showStatusMessage(QString,bool)),
this, SLOT(slotShowStatusMessage(QString,bool)));
connect( temp, SIGNAL( sigBusy( bool ) ), this, SLOT( slotBusy( bool ) ) );
tabPosts->addTab( temp, post.title() );
// if(tabPosts->count() == 1)
// tabPosts->setTabBarHidden(true);
// else
// tabPosts->setTabBarHidden(false);
return temp;
}
void MainWindow::slotShowStatusMessage(const QString &message, bool isPermanent)
{
statusBar()->showMessage(message, (isPermanent ? 0 : TIMEOUT));
}
void MainWindow::uploadMediaObject()
{
UploadMediaDialog *uploadDlg = new UploadMediaDialog(this);
connect(uploadDlg, SIGNAL(sigBusy(bool)), SLOT(slotBusy(bool)));
if(mCurrentBlogId == -1)
uploadDlg->init( 0 );
else
uploadDlg->init( DBMan::self()->blog(mCurrentBlogId) );
}
void MainWindow::slotOpenCurrentBlogInBrowser()
{
if (mCurrentBlogId > -1) {
KUrl url( DBMan::self()->blog( mCurrentBlogId )->blogUrl() );
if(url.isValid())
KToolInvocation::invokeBrowser(url.url());
else
KMessageBox::sorry(this, i18n("Cannot find current blog URL."));
}
///TODO
///else show a massege to the user saying that a blog should be selected before.
}
#include "mainwindow.moc"
diff --git a/knode/foldertreewidget.cpp b/knode/foldertreewidget.cpp
index d866c1937e..85f0c7f53e 100644
--- a/knode/foldertreewidget.cpp
+++ b/knode/foldertreewidget.cpp
@@ -1,618 +1,621 @@
/******************************************************************************
*
* This file is part of libkdepim.
*
* Copyright (C) 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*****************************************************************************/
#include "foldertreewidget.h"
#include <kio/global.h> // for KIO::filesize_t and related functions
#include <klineedit.h>
#include <klocale.h>
#include <QHeaderView>
#include <QDropEvent>
#include <QMimeData>
#include <QStyledItemDelegate>
#include <QStyle>
#include <QPainter>
#include <QFontMetrics>
#include <QApplication>
#define FOLDERTREEWIDGETITEM_TYPE ( QTreeWidgetItem::UserType + 0xcafe )
namespace KPIM {
#define ITEM_LABEL_RIGHT_MARGIN 2
#define ITEM_LABEL_TO_UNREADCOUNT_SPACING 2
class FolderTreeWidgetItemLabelColumnDelegate : public QStyledItemDelegate
{
protected:
FolderTreeWidget *mFolderTreeWidget;
public:
FolderTreeWidgetItemLabelColumnDelegate( FolderTreeWidget *parent )
: QStyledItemDelegate( parent ), mFolderTreeWidget( parent ) {};
~FolderTreeWidgetItemLabelColumnDelegate()
{};
virtual QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
QStyleOptionViewItemV4 opt = option;
initStyleOption( &opt, index );
opt.text = "X"; // fake a text (so the height is computed correctly)
opt.features |= QStyleOptionViewItemV2::HasDisplay;
return mFolderTreeWidget->style()->sizeFromContents( QStyle::CT_ItemViewItem, &opt, QSize(), mFolderTreeWidget );
}
virtual void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
//
// The equilibrism in this function attempts to rely on QStyle for most of the job.
//
QStyleOptionViewItemV4 opt = option;
initStyleOption( &opt, index );
opt.text = ""; // draw no text for me, please.. I'll do it in a while
QStyle * style = mFolderTreeWidget->style();
style->drawControl( QStyle::CE_ItemViewItem, &opt, painter, mFolderTreeWidget );
// FIXME: this is plain ugly :D
// OTOH seaching the item by model index is extremely expensive when compared to a cast.
// We're also using static_cast<> instead of dynamic_cast<> to avoid performance loss:
// we actually trust the developer to add only real FolderTreeWidgetItems to this widget.
FolderTreeWidgetItem * item = static_cast<FolderTreeWidgetItem *>( index.internalPointer() );
if ( !item )
return; // ugh :/
// draw the labelText().
QRect textRect = style->subElementRect( QStyle::SE_ItemViewItemText, &opt, mFolderTreeWidget );
textRect.setWidth( textRect.width() - ITEM_LABEL_RIGHT_MARGIN );
// keeping indipendent state variables is faster than saving and restoring the whole painter state
QPen oldPen = painter->pen();
QFont oldFont = painter->font();
if ( item->isCloseToQuota() && ( !( opt.state & QStyle::State_Selected ) ) )
{
painter->setPen( QPen( mFolderTreeWidget->closeToQuotaWarningColor(), 0 ) );
} else {
QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active))
cg = QPalette::Inactive;
QPalette::ColorRole cr = ( opt.state & QStyle::State_Selected ) ? QPalette::HighlightedText : QPalette::Text;
painter->setPen( QPen( opt.palette.brush( cg, cr ), 0 ) );
}
int unread = item->unreadCount();
int childUnread = item->childrenUnreadCount();
bool displayChildUnread = ( childUnread > 0 ) && ( !item->isExpanded() );
if ( ( unread > 0 ) || displayChildUnread )
{
// font is bold for sure (unread stuff in folder)
QFont f = opt.font;
f.setBold( true );
painter->setFont( f );
QFontMetrics fm( painter->font() ); // use the bold font metrics
if (
( mFolderTreeWidget->unreadColumnIndex() == -1 ) ||
mFolderTreeWidget->isColumnHidden( mFolderTreeWidget->unreadColumnIndex() )
)
{
// we need to paint the unread count too
QString unreadText;
if ( unread > 0 )
{
if ( displayChildUnread )
unreadText = QString("(%1 + %2)").arg( unread ).arg( childUnread );
else
unreadText = QString("(%1)").arg( unread );
} else
unreadText = QString("(0 + %1)").arg( childUnread );
// compute the potential width so we know if elision has to be performed
int unreadWidth = fm.width( unreadText );
int labelWidth = fm.width( item->labelText() );
int maxWidth = labelWidth + ITEM_LABEL_TO_UNREADCOUNT_SPACING + unreadWidth;
QString label;
if ( maxWidth > textRect.width() )
{
// must elide
label = item->elidedLabelText( fm, textRect.width() - ( ITEM_LABEL_TO_UNREADCOUNT_SPACING + unreadWidth ) );
labelWidth = fm.width( label );
// the condition inside this call is an optimization (it's faster than simply label != item->labelText())
item->setLabelTextElided( ( label.length() != item->labelText().length() ) || ( label != item->labelText() ) );
} else {
label = item->labelText();
// no elision needed
item->setLabelTextElided( false );
}
painter->drawText( textRect, Qt::AlignLeft | Qt::TextSingleLine | Qt::AlignVCenter, label );
if ( QApplication::isLeftToRight() )
textRect.setLeft( textRect.left() + labelWidth + ITEM_LABEL_TO_UNREADCOUNT_SPACING );
else
textRect.setRight( textRect.right() - labelWidth - ITEM_LABEL_TO_UNREADCOUNT_SPACING );
if ( !( opt.state & QStyle::State_Selected ) ) {
painter->setPen( QPen( mFolderTreeWidget->unreadCountColor(), 0 ) );
}
painter->drawText( textRect, Qt::AlignLeft | Qt::TextSingleLine | Qt::AlignVCenter, unreadText );
} else {
// got unread messages: bold font but no special text tricks
QString label = item->elidedLabelText( fm, textRect.width() );
// the condition inside this call is an optimization (it's faster than simply label != item->labelText())
item->setLabelTextElided( ( label.length() != item->labelText().length() ) || ( label != item->labelText() ) );
painter->drawText( textRect, Qt::AlignLeft | Qt::TextSingleLine | Qt::AlignVCenter, label );
}
} else {
// no unread messages: normal font, no text tricks
QString label = item->elidedLabelText( opt.fontMetrics, textRect.width() );
// the condition inside this call is an optimization (it's faster than simply label != item->labelText())
item->setLabelTextElided( ( label.length() != item->labelText().length() ) || ( label != item->labelText() ) );
painter->setFont( opt.font );
painter->drawText( textRect, Qt::AlignLeft | Qt::TextSingleLine | Qt::AlignVCenter, label );
}
painter->setPen( oldPen );
painter->setFont( oldFont );
}
virtual void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QStyledItemDelegate::setModelData( editor, model, index );
FolderTreeWidgetItem *item = static_cast<FolderTreeWidgetItem *>( index.internalPointer() );
if ( item ) {
// test if old text != new text
if( item->labelText() != item->text( mFolderTreeWidget->labelColumnIndex() ) ) {
item->setLabelText( item->text( mFolderTreeWidget->labelColumnIndex() ) );
mFolderTreeWidget->emitRenamed( item );
}
}
}
};
FolderTreeWidget::FolderTreeWidget( QWidget *parent , const char *name )
: KPIM::TreeWidget( parent , name ),
mUnreadCountColor( Qt::blue ), mCloseToQuotaWarningColor( Qt::red )
{
mLabelColumnIndex = -1;
mUnreadColumnIndex = -1;
mTotalColumnIndex = -1;
mDataSizeColumnIndex = -1;
setAlternatingRowColors( true );
setAcceptDrops( true );
setAllColumnsShowFocus( true );
setRootIsDecorated( true );
setSortingEnabled( true );
setUniformRowHeights( true ); // optimize please
//setAnimated( true ); // this slows down everything a lot
header()->setSortIndicatorShown( true );
header()->setClickable( true );
//setSelectionMode( Extended );
connect( this, SIGNAL( itemExpanded( QTreeWidgetItem * ) ),
SLOT( updateExpandedState( QTreeWidgetItem * ) ) );
connect( this, SIGNAL( itemCollapsed( QTreeWidgetItem * ) ),
SLOT( updateExpandedState( QTreeWidgetItem * ) ) );
}
int FolderTreeWidget::addLabelColumn( const QString &headerLabel )
{
if ( mLabelColumnIndex == -1 )
{
mLabelColumnIndex = addColumn( headerLabel );
setItemDelegateForColumn( mLabelColumnIndex, new FolderTreeWidgetItemLabelColumnDelegate( this ) );
}
return mLabelColumnIndex;
}
bool FolderTreeWidget::labelColumnVisible() const
{
if ( mLabelColumnIndex == -1 )
return false;
return !isColumnHidden( mLabelColumnIndex );
}
int FolderTreeWidget::addTotalColumn( const QString &headerLabel )
{
if ( mTotalColumnIndex == -1 )
mTotalColumnIndex = addColumn( headerLabel , Qt::AlignRight );
return mTotalColumnIndex;
}
bool FolderTreeWidget::totalColumnVisible() const
{
if ( mTotalColumnIndex == -1 )
return false;
return !isColumnHidden( mTotalColumnIndex );
}
int FolderTreeWidget::addUnreadColumn( const QString &headerLabel )
{
if ( mUnreadColumnIndex == -1 )
mUnreadColumnIndex = addColumn( headerLabel , Qt::AlignRight );
return mUnreadColumnIndex;
}
bool FolderTreeWidget::unreadColumnVisible() const
{
if ( mUnreadColumnIndex == -1 )
return false;
return !isColumnHidden( mUnreadColumnIndex );
}
int FolderTreeWidget::addDataSizeColumn( const QString &headerLabel )
{
if ( mDataSizeColumnIndex == -1 )
mDataSizeColumnIndex = addColumn( headerLabel , Qt::AlignRight );
return mDataSizeColumnIndex;
}
bool FolderTreeWidget::dataSizeColumnVisible() const
{
if ( mDataSizeColumnIndex == -1 )
return false;
return !isColumnHidden( mDataSizeColumnIndex );
}
void FolderTreeWidget::updateColumnForItem( FolderTreeWidgetItem * item, int columnIndex )
{
update( indexFromItem( item, columnIndex ) );
}
void FolderTreeWidget::updateExpandedState( QTreeWidgetItem *item )
{
FolderTreeWidgetItem *folderItem = dynamic_cast<FolderTreeWidgetItem*>( item );
Q_ASSERT( folderItem );
if ( folderItem )
folderItem->updateExpandedState();
}
void FolderTreeWidget::setCloseToQuotaWarningColor( const QColor &clr )
{
mCloseToQuotaWarningColor = clr;
update();
}
void FolderTreeWidget::setUnreadCountColor( const QColor &clr )
{
mUnreadCountColor = clr;
update();
}
void FolderTreeWidget::emitRenamed( QTreeWidgetItem *item )
{
emit renamed( item );
}
FolderTreeWidgetItem::FolderTreeWidgetItem(
FolderTreeWidget *parent,
const QString &label,
Protocol protocol,
FolderType folderType
) : QTreeWidgetItem( parent, FOLDERTREEWIDGETITEM_TYPE ),
mProtocol( protocol ), mFolderType( folderType ), mLabelText( label ),
mTotalCount( 0 ), mUnreadCount( 0 ), mDataSize( -1 ), mIsCloseToQuota( 0 ),
mLabelTextElided( 0 ), mChildrenTotalCount( 0 ), mChildrenUnreadCount( 0 ),
mChildrenDataSize( -1 ), mAlwaysDisplayCounts( false )
{
setText( parent->labelColumnIndex(), label );
}
FolderTreeWidgetItem::FolderTreeWidgetItem(
FolderTreeWidgetItem *parent,
const QString &label,
Protocol protocol,
FolderType folderType
) : QTreeWidgetItem( parent, FOLDERTREEWIDGETITEM_TYPE ),
mProtocol( protocol ), mFolderType( folderType ), mLabelText( label ),
mTotalCount( 0 ), mUnreadCount( 0 ), mDataSize( -1 ), mIsCloseToQuota( 0 ),
mLabelTextElided( 0 ), mChildrenTotalCount( 0 ), mChildrenUnreadCount( 0 ),
mChildrenDataSize( -1 ), mAlwaysDisplayCounts( false )
{
FolderTreeWidget * tree = dynamic_cast< FolderTreeWidget * >( treeWidget() );
if ( tree )
setText( tree->labelColumnIndex(), label );
}
QString FolderTreeWidgetItem::protocolDescription() const
{
switch( mProtocol )
{
case Local:
return i18n( "Local" );
break;
case Imap:
return i18n( "IMAP" );
break;
case CachedImap:
return i18n( "Cached IMAP" );
break;
case News:
return i18n( "News" );
break;
case Search:
return i18n( "Search" );
break;
case NONE:
return i18n( "None" );
break;
default:
break;
}
return i18n( "Unknown" );
}
bool FolderTreeWidgetItem::updateChildrenCounts()
{
int cc = childCount();
if ( cc < 1 )
return false;
int idx = 0;
int oldTotal = mChildrenTotalCount;
int oldUnread = mChildrenUnreadCount;
qint64 oldSize = mChildrenDataSize;
mChildrenTotalCount = 0;
mChildrenUnreadCount = 0;
mChildrenDataSize = 0;
bool gotValidDataSize = false;
while ( idx < cc )
{
FolderTreeWidgetItem *it = static_cast< FolderTreeWidgetItem * >( QTreeWidgetItem::child( idx ) );
mChildrenTotalCount += it->totalCount() + it->childrenTotalCount();
mChildrenUnreadCount += it->unreadCount() + it->childrenUnreadCount();
if ( it->dataSize() >= 0)
{
gotValidDataSize = true;
mChildrenDataSize += it->dataSize();
}
if ( it->childrenDataSize() >= 0 )
{
gotValidDataSize = true;
mChildrenDataSize += it->childrenDataSize();
}
idx++;
}
if ( !gotValidDataSize )
mChildrenDataSize = -1; // keep it invald
return ( oldTotal != mChildrenTotalCount ) ||
( oldUnread != mChildrenUnreadCount ) ||
( oldSize != mChildrenDataSize );
}
void FolderTreeWidgetItem::setLabelText( const QString &label )
{
mLabelText = label;
// We set the text of the item so QStyle will compute the height correctly
FolderTreeWidget * tree = dynamic_cast< FolderTreeWidget * >( treeWidget() );
int idx = tree->labelColumnIndex();
if ( tree && idx >= 0 )
{
setText( idx, label );
setTextAlignment( idx, Qt::AlignRight );
}
}
void FolderTreeWidgetItem::setUnreadCount( int unreadCount )
{
mUnreadCount = unreadCount;
int unreadCountToDisplay = unreadCount;
if ( mChildrenUnreadCount > 0 && !isExpanded() )
unreadCountToDisplay += mChildrenUnreadCount;
FolderTreeWidget * tree = dynamic_cast< FolderTreeWidget * >( treeWidget() );
- int idx = tree->unreadColumnIndex();
- if ( tree && idx >= 0 )
+ if ( tree )
{
- if ( ( parent() || mAlwaysDisplayCounts || !isExpanded() ) && unreadCountToDisplay > 0 )
- setText( idx, QString::number( unreadCountToDisplay ) );
- else
- setText( idx, QString() );
+ int idx = tree->unreadColumnIndex();
+ if ( idx >= 0 )
+ {
+ if ( ( parent() || mAlwaysDisplayCounts || !isExpanded() ) && unreadCountToDisplay > 0 )
+ setText( idx, QString::number( unreadCountToDisplay ) );
+ else
+ setText( idx, QString() );
+ }
setTextAlignment( idx, Qt::AlignRight );
}
}
void FolderTreeWidgetItem::setTotalCount( int totalCount )
{
mTotalCount = totalCount;
int totalCountToDisplay = totalCount;
if ( mChildrenTotalCount > 0 && !isExpanded() )
totalCountToDisplay += mChildrenTotalCount;
FolderTreeWidget * tree = dynamic_cast< FolderTreeWidget * >( treeWidget() );
int idx = tree->totalColumnIndex();
if ( tree && idx >= 0 )
{
// FIXME: Why the "parent()" logic is hardwired here ?
if ( parent() || mAlwaysDisplayCounts || !isExpanded() )
setText( idx, QString::number( totalCountToDisplay ) );
else
setText( idx, QString() );
setTextAlignment( idx, Qt::AlignRight );
}
}
void FolderTreeWidgetItem::setDataSize( qint64 dataSize )
{
mDataSize = dataSize;
QString txt;
QString sizeText = KIO::convertSize( mDataSize >= 0 ? (KIO::filesize_t)mDataSize : (KIO::filesize_t)0 );
QString childSizeText = KIO::convertSize( (KIO::filesize_t)mChildrenDataSize );
// A top level item, they all have size 0
// FIXME: Why this logic is hardwired here ?
if ( !parent() && !mAlwaysDisplayCounts ) {
if ( mChildrenDataSize >= 0 && !isExpanded() )
txt = childSizeText;
else
txt = QString();
}
// Not a top level item (or always displays counts)
else if ( ( mDataSize >= 0 ) || ( mChildrenDataSize >= 0 ) ) {
txt = sizeText;
if ( !isExpanded() ) {
if ( mChildrenDataSize >= 0 )
txt += " + " + childSizeText;
}
}
else
txt = "-";
FolderTreeWidget * tree = dynamic_cast< FolderTreeWidget * >( treeWidget() );
int idx = tree->dataSizeColumnIndex();
if ( tree && idx >= 0 )
{
setText( idx, txt );
setTextAlignment( idx, Qt::AlignRight );
}
}
void FolderTreeWidgetItem::updateExpandedState()
{
// Just trigger an update of the column text, it will all be handled thaere.
setDataSize( mDataSize );
setTotalCount( mTotalCount );
setUnreadCount( mUnreadCount );
}
void FolderTreeWidgetItem::updateColumn( int columnIndex )
{
FolderTreeWidget * tree = dynamic_cast< FolderTreeWidget * >( treeWidget() );
if ( tree ) {
tree->updateColumnForItem( this, columnIndex );
if ( columnIndex!=tree->labelColumnIndex() && !tree->unreadColumnVisible() && tree->labelColumnVisible() ) {
updateColumn( tree->labelColumnIndex() );
}
}
}
void FolderTreeWidgetItem::setIsCloseToQuota( bool closeToQuota )
{
if ( ( mIsCloseToQuota == 1 ) == closeToQuota )
return;
mIsCloseToQuota = closeToQuota ? 1 : 0;
FolderTreeWidget * tree = dynamic_cast< FolderTreeWidget * >( treeWidget() );
if ( tree && tree->labelColumnVisible() )
updateColumn( tree->labelColumnIndex() );
}
bool FolderTreeWidgetItem::operator < ( const QTreeWidgetItem &other ) const
{
// FIXME: Sort by children counts too ?
int sortCol = treeWidget()->sortColumn();
if ( sortCol < 0 )
return true; // just "yes" :D
FolderTreeWidget * w = dynamic_cast< FolderTreeWidget * >( treeWidget() );
if ( w )
{
// sanity check
if ( dynamic_cast<const FolderTreeWidgetItem*>( &other ) )
{
const FolderTreeWidgetItem * oitem = dynamic_cast< const FolderTreeWidgetItem * >( &other );
if ( oitem )
{
if ( sortCol == w->unreadColumnIndex() )
return mUnreadCount < oitem->unreadCount();
if ( sortCol == w->totalColumnIndex() )
return mTotalCount < oitem->totalCount();
if ( sortCol == w->dataSizeColumnIndex() )
return mDataSize < oitem->dataSize();
if ( sortCol == w->labelColumnIndex() )
{
// Special sorting based on the item type
int thisProto = ( int ) mProtocol;
int thatProto = ( int ) oitem->protocol();
if ( thisProto < thatProto )
return true;
if ( thisProto > thatProto )
return false;
int thisType = ( int ) mFolderType;
int thatType = ( int ) oitem->folderType();
if ( thisType < thatType )
return true;
if ( thisType > thatType )
return false;
// and finally compare by name
return mLabelText.toLower() < oitem->labelText().toLower();
}
}
}
}
return text(sortCol) < other.text(sortCol);
}
QString FolderTreeWidgetItem::elidedLabelText( const QFontMetrics &metrics, unsigned int width ) const
{
return metrics.elidedText( labelText(), Qt::ElideRight, width );
}
}
#include "foldertreewidget.moc"
diff --git a/knode/knjobdata.cpp b/knode/knjobdata.cpp
index ac5971b4ae..a521fd99cb 100644
--- a/knode/knjobdata.cpp
+++ b/knode/knjobdata.cpp
@@ -1,207 +1,207 @@
/*
KNode, the KDE newsreader
Copyright (c) 1999-2005 the KNode authors.
See file AUTHORS for details
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/
#include <kdebug.h>
#include <klocale.h>
#include <kio/job.h>
#include <libkdepim/progressmanager.h>
#include "knarticle.h"
#include "knglobals.h"
#include "knnntpaccount.h"
#include "scheduler.h"
//Added by qt3to4:
#include <QTimer>
KNJobConsumer::KNJobConsumer()
{
}
KNJobConsumer::~KNJobConsumer()
{
for ( QList<KNJobData*>::Iterator it = mJobs.begin(); it != mJobs.end(); ++it )
(*it)->c_onsumer = 0;
}
void KNJobConsumer::emitJob( KNJobData *j )
{
if ( j ) {
mJobs.append( j );
knGlobals.scheduler()->addJob( j );
}
}
void KNJobConsumer::jobDone( KNJobData *j )
{
if ( j && mJobs.removeAll( j ) )
processJob( j );
}
void KNJobConsumer::cancelJobs( KNJobItem::Ptr item )
{
Q_FOREACH( KNJobData *job, mJobs ) {
if ( job->data() == item ) {
job->d_ata.reset();
job->cancel();
}
}
}
void KNJobConsumer::processJob( KNJobData *j )
{
delete j;
}
// the assingment of a_ccount may cause race conditions, check again.... (CG)
KNJobData::KNJobData( jobType t, KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i ) :
t_ype(t), d_ata(i), a_ccount(a),
mError( 0 ),
mCanceled( false ),
c_onsumer( c ),
mJob( 0 ),
mProgressItem( 0 )
{
d_ata->setLocked(true);
}
KNJobData::~KNJobData()
{
if ( d_ata ) {
d_ata->setLocked( false );
}
}
void KNJobData::notifyConsumer()
{
if(c_onsumer)
c_onsumer->jobDone(this);
else
delete this;
}
void KNJobData::cancel()
{
mCanceled = true;
if ( mJob ) {
mJob->kill();
}
if ( mProgressItem ) {
mProgressItem->setStatus( "Canceled" );
mProgressItem->setComplete();
mProgressItem = 0;
}
emitFinished();
}
void KNJobData::emitFinished()
{
QTimer::singleShot( 0, this, SLOT(slotEmitFinished()) );
}
void KNJobData::setupKJob(KJob * job)
{
mJob = job;
if ( job ) {
connect( job, SIGNAL( percent(KJob*, unsigned long) ),
SLOT( slotJobPercent(KJob*, unsigned long) ) );
connect( job, SIGNAL( infoMessage(KJob*, const QString&) ),
SLOT( slotJobInfoMessage(KJob*, const QString&) ) );
}
}
void KNJobData::setupKIOJob( KIO::Job *job )
{
if ( job ) {
if ( account() ) {
if ( account()->encryption() == KNServerInfo::TLS )
job->addMetaData( "tls", "on" );
else
job->addMetaData( "tls", "off" );
}
- }
job->setUiDelegate(0);
setupKJob( job );
+ }
}
void KNJobData::createProgressItem()
{
if ( mProgressItem )
return;
KNNntpAccount::Ptr acc = boost::static_pointer_cast<KNNntpAccount>( account() );
QString msg = i18n( "KNode" );
if ( type() == JTmail )
msg = i18n( "Sending message" );
else {
if ( acc )
msg = acc->name();
}
bool encr = false;
if ( acc && acc->encryption() != KNServerInfo::None )
encr = true;
mProgressItem = KPIM::ProgressManager::createProgressItem( 0,
KPIM::ProgressManager::getUniqueID(), msg, i18n( "Waiting..." ), true, encr );
}
void KNJobData::slotJobPercent( KJob*, unsigned long percent )
{
kDebug(5003) <<"Progress:" << percent;
setProgress( percent );
}
void KNJobData::slotJobInfoMessage( KJob*, const QString &msg )
{
kDebug(5003) <<"Status:" << msg;
setStatus( msg );
}
void KNJobData::slotEmitFinished( )
{
emit finished( this );
}
KUrl KNJobData::baseUrl() const
{
KUrl url;
if ( account()->encryption() == KNServerInfo::SSL )
url.setProtocol( "nntps" );
else
url.setProtocol( "nntp" );
url.setHost( account()->server() );
url.setPort( account()->port() );
if ( account()->needsLogon() ) {
url.setUser( account()->user() );
url.setPass( account()->pass() );
}
return url;
}
void KNJobData::setError( int err, const QString & errMsg )
{
mError = err;
mErrorString = errMsg;
}
#include "knjobdata.moc"

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 1, 10:01 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10076280
Default Alt Text
(49 KB)

Event Timeline