• 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
  • composer
bilbobrowser.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 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License or (at your option) version 3 or any later version
11  accepted by the membership of KDE e.V. (or its successor approved
12  by the membership of KDE e.V.), which shall act as a proxy
13  defined in Section 14 of version 3 of the license.
14 
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, see http://www.gnu.org/licenses/
23 */
24 //krazy:excludeall=qmethods due to use of KStatusBar::showMessage()
25 
26 #include "bilbobrowser.h"
27 
28 #include <KWebView>
29 #include <QProgressBar>
30 #include <kstatusbar.h>
31 #include <kmessagebox.h>
32 #include <kseparator.h>
33 #include <kpushbutton.h>
34 
35 #include "stylegetter.h"
36 #include "global.h"
37 #include "settings.h"
38 #include <klocalizedstring.h>
39 #include <dbman.h>
40 #include <bilboblog.h>
41 #include <qcheckbox.h>
42 #include <QVBoxLayout>
43 #include <QTimer>
44 
45 BilboBrowser::BilboBrowser( QWidget *parent )
46  : QWidget( parent )
47 {
48  mWebView = new KWebView(this);
49 
50  createUi( parent );
51 
52  connect( mWebView, SIGNAL(loadProgress(int)),
53  browserProgress, SLOT(setValue(int)) );
54  connect( mWebView, SIGNAL(loadFinished(bool)) , this, SLOT(slotCompleted(bool)) );
55  connect( mWebView, SIGNAL(statusBarMessage(QString)), this,
56  SLOT(slotSetStatusBarText(QString)) );
57 }
58 
59 BilboBrowser::~BilboBrowser()
60 {
61  kDebug();
62 }
63 
64 void BilboBrowser::createUi( QWidget *parent )
65 {
66  btnGetStyle = new KPushButton( this );
67  btnGetStyle->setText( i18n( "Get blog style" ) );
68  connect( btnGetStyle, SIGNAL(clicked(bool)), this, SLOT(slotGetBlogStyle()) );
69 
70  viewInBlogStyle = new QCheckBox( i18n("View post in the blog style"), this );
71  viewInBlogStyle->setChecked( Settings::previewInBlogStyle() );
72  connect( viewInBlogStyle, SIGNAL(toggled(bool)), this, SLOT(
73  slotViewModeChanged() ) );
74 
75  QSpacerItem *horizontalSpacer = new QSpacerItem( 40, 20,
76  QSizePolicy::Expanding, QSizePolicy::Minimum );
77  KSeparator *separator = new KSeparator( this );
78 
79  QVBoxLayout *vlayout = new QVBoxLayout( parent );
80  QHBoxLayout *hlayout = new QHBoxLayout();
81 
82  hlayout->addWidget( viewInBlogStyle );
83  hlayout->addItem( horizontalSpacer );
84  hlayout->addWidget( btnGetStyle );
85 
86  vlayout->addLayout( hlayout );
87  vlayout->addWidget( separator );
88  vlayout->addWidget( mWebView );
89 
90  browserProgress = new QProgressBar( this );
91  browserProgress->setFixedSize(120, 17);
92 
93  browserStatus = new KStatusBar( this );
94  browserStatus->setFixedHeight( 20 );
95  browserStatus->addPermanentWidget( browserProgress );
96  vlayout->addWidget( browserStatus );
97 }
98 
99 void BilboBrowser::setHtml( const QString& title, const QString& content )
100 {
101  currentTitle = title;
102  currentContent = content;
103 
104  if ( browserProgress->isHidden() ) {
105  browserProgress->show();
106  }
107  browserProgress->reset();
108  browserStatus->showMessage( i18n( "loading page items..." ) );
109 
110  if ( viewInBlogStyle->isChecked() ) {
111  mWebView->setHtml( StyleGetter::styledHtml( __currentBlogId, title, content ),
112  DBMan::self()->blog(__currentBlogId)->url());
113  } else {
114  mWebView->setHtml( QLatin1String("<html><body><h2 align='center'>") + title + QLatin1String("</h2>") + content + QLatin1String("</html>") );
115  }
116 }
117 
118 void BilboBrowser::stop()
119 {
120  mWebView->stop();
121 }
122 
123 void BilboBrowser::slotGetBlogStyle()
124 {
125  stop();
126  if ( __currentBlogId < 0 ) {
127  KMessageBox::information( this,
128  i18n( "Please select a blog, then try again." ),
129  i18n( "Select a blog" ) );
130  return;
131  }
132 
133  browserStatus->showMessage( i18n( "Fetching blog style from the web..." ) );
134  if ( browserProgress->isHidden() ) {
135  browserProgress->show();
136  }
137  browserProgress->reset();
138 
139  StyleGetter *styleGetter = new StyleGetter( __currentBlogId, this );
140  connect( styleGetter, SIGNAL(sigGetStyleProgress(int)), browserProgress,
141  SLOT(setValue(int)) );
142  connect( styleGetter, SIGNAL(sigStyleFetched()), this, SLOT(slotSetBlogStyle()) );
143 }
144 
145 void BilboBrowser::slotSetBlogStyle()
146 {
147  browserStatus->showMessage( i18n( "Blog style fetched." ), 2000 );
148  Q_EMIT sigSetBlogStyle();
149 
150  if ( qobject_cast< StyleGetter* >( sender() ) ) {
151  sender()->deleteLater();
152  }
153 }
154 
155 void BilboBrowser::slotCompleted(bool ok)
156 {
157  QTimer::singleShot( 1500, browserProgress, SLOT(hide()) );
158  if(!ok){
159  browserStatus->showMessage( i18n( "An error occurred in the latest transaction." ), 5000 );
160  }
161 }
162 
163 void BilboBrowser::slotSetStatusBarText( const QString& text )
164 {
165  QString statusText = text;
166  statusText.remove( QLatin1String("<qt>") );
167  browserStatus->showMessage( statusText );
168 }
169 
170 void BilboBrowser::slotViewModeChanged()
171 {
172  stop();
173  setHtml( currentTitle, currentContent );
174 }
175 
QSpacerItem
QProgressBar
QWidget
QWidget::isHidden
bool isHidden() const
BilboBrowser::slotGetBlogStyle
void slotGetBlogStyle()
Definition: bilbobrowser.cpp:123
QObject::sender
QObject * sender() const
BilboBrowser::slotSetStatusBarText
void slotSetStatusBarText(const QString &text)
Definition: bilbobrowser.cpp:163
QHBoxLayout
DBMan::self
static DBMan * self()
Retrieve the instance of DataBase Manager.
Definition: dbman.cpp:117
bilbobrowser.h
QString::remove
QString & remove(int position, int n)
BilboBrowser::sigSetBlogStyle
void sigSetBlogStyle()
This signal is emmited when the browser finishes getting blog style.
global.h
StyleGetter::styledHtml
static QString styledHtml(const int blogid, const QString &title, const QString &content)
Looks for a file named style.html for the requested blog in blogilo data directory, then writes the file content into a buffer, inserts given post title and content in the buffer, and returns it.
Definition: stylegetter.cpp:98
StyleGetter
This class will:
Definition: stylegetter.h:51
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
BilboBrowser::BilboBrowser
BilboBrowser(QWidget *parent=0)
BilboBrowser constructor.
Definition: bilbobrowser.cpp:45
__currentBlogId
int __currentBlogId
Global variables.
Definition: global.cpp:29
QCheckBox
QBoxLayout::addItem
virtual void addItem(QLayoutItem *item)
QVBoxLayout
BilboBrowser::setHtml
void setHtml(const QString &title, const QString &content)
Shows a post with given title and content in the browser.
Definition: bilbobrowser.cpp:99
QObject::deleteLater
void deleteLater()
BilboBrowser::slotCompleted
void slotCompleted(bool)
Definition: bilbobrowser.cpp:155
QString
QWidget::hide
void hide()
bilboblog.h
BilboBrowser::slotSetBlogStyle
void slotSetBlogStyle()
Definition: bilbobrowser.cpp:145
QWidget::setFixedSize
void setFixedSize(const QSize &s)
QAbstractButton::setChecked
void setChecked(bool)
dbman.h
QLatin1String
QWidget::show
void show()
BilboBrowser::stop
void stop()
Definition: bilbobrowser.cpp:118
QProgressBar::reset
void reset()
stylegetter.h
BilboBrowser::~BilboBrowser
~BilboBrowser()
BilboBrowser destructor.
Definition: bilbobrowser.cpp:59
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
BilboBrowser::slotViewModeChanged
void slotViewModeChanged()
Definition: bilbobrowser.cpp:170
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
QTimer::singleShot
singleShot
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