42 #include <libkdepim/widgets/spellchecklineedit.h>
46 #include <klocalizedstring.h>
47 #include <klineedit.h>
48 #include <KMessageBox>
49 #include <ktexteditor/view.h>
50 #include <ktexteditor/document.h>
54 #include <QProgressBar>
58 #include <QHBoxLayout>
62 class PostEntry::Private
69 KPIM::SpellCheckLineEdit *txtTitle;
72 int mCurrentPostBlogId;
75 int mNumOfFilesToBeUploaded;
76 bool isUploadingMediaFilesFailed;
78 bool isPostContentModified;
87 KTextEditor::View *htmlEditor;
94 :
QFrame( parent ), d(new Private)
101 d->mTimer =
new QTimer(
this);
102 d->mTimer->start(Settings::autosaveInterval() *
MINUTE);
105 d->mCurrentPostBlogId = -1;
106 d->mNumOfFilesToBeUploaded = 0;
107 d->isPostContentModified =
false;
119 d->mTimer->setInterval(Settings::autosaveInterval() *
MINUTE);
120 if (Settings::autosaveInterval())
126 void PostEntry::createUi()
129 d->tabVisual =
new QWidget( d->tabWidget );
130 d->tabHtml =
new QWidget( d->tabWidget );
131 d->tabPreview =
new QWidget( d->tabWidget );
132 d->tabWidget->addTab( d->tabVisual, i18nc(
"Software",
"Visual Editor" ) );
133 d->tabWidget->addTab( d->tabHtml, i18nc(
"Software",
"Html Editor" ) );
134 d->tabWidget->addTab( d->tabPreview, i18nc(
"preview of the edited post",
"Post Preview" ) );
157 d->tabWidget->setCurrentIndex( 0 );
162 d->horizontalLayout->setSizeConstraint( QLayout::SetDefaultConstraint );
164 d->labelTitle =
new QLabel(
this );
165 d->labelTitle->setText( i18nc(
"noun, the post title",
"Title:" ) );
166 d->horizontalLayout->addWidget( d->labelTitle );
168 d->txtTitle =
new KPIM::SpellCheckLineEdit(
this,
QLatin1String(
"blogilorc" ) );
169 d->horizontalLayout->addWidget( d->txtTitle );
170 d->labelTitle->setBuddy( d->txtTitle );
175 d->gridLayout->addLayout( d->horizontalLayout, 0, 0, 1, 1 );
180 switch(d->tabWidget->currentIndex()) {
182 d->wysiwygEditor->editor()->startEditing();
185 d->htmlEditor->setFocus();
193 if ( d->prev_index == 2 ) {
194 d->previewer->stop();
195 d->prev_index = index;
198 d->wysiwygEditor->editor()->setHtmlContent(d->htmlEditor->document()->text());
199 d->wysiwygEditor->editor()->setFocus();
200 d->wysiwygEditor->editor()->startEditing();
201 }
else if ( index == 1 ) {
202 if ( d->prev_index == 2 ) {
203 d->previewer->stop();
204 d->prev_index = index;
207 d->htmlEditor->document()->setText( d->wysiwygEditor->editor()->htmlContent() );
208 d->htmlEditor->setFocus();
210 if ( d->prev_index == 1 ) {
211 d->wysiwygEditor->editor()->setHtmlContent(d->htmlEditor->document()->text());
213 d->htmlEditor->document()->setText( d->wysiwygEditor->editor()->htmlContent() );
215 d->previewer->setHtml( d->txtTitle->toPlainText(), d->htmlEditor->document()->text() );
217 d->prev_index = index;
222 if ( d->tabWidget->currentIndex() == 2 ) {
223 d->previewer->setHtml( d->txtTitle->toPlainText(), d->htmlEditor->document()->text() );
229 if ( d->tabWidget->currentIndex() == 1 ) {
230 d->wysiwygEditor->editor()->setHtmlContent( d->htmlEditor->document()->text() );
232 d->htmlEditor->document()->setText( d->wysiwygEditor->editor()->htmlContent() );
234 return d->htmlEditor->document()->text();
239 return d->wysiwygEditor->editor()->plainTextContent();
244 d->wysiwygEditor->editor()->setHtmlContent(content);
245 d->htmlEditor->document()->setText( content );
250 const QString titleText(d->txtTitle->toPlainText());
251 d->mCurrentPost.setTitle(titleText);
257 return d->mCurrentPost.title();
262 d->txtTitle->setPlainText( title );
263 d->mCurrentPost.setTitle( title );
269 if (additionalContent.
isEmpty()) {
272 body = content +
QLatin1String(
"<hr/><!--split-->") + additionalContent;
273 d->mCurrentPost.setAdditionalContent(
QString());
278 d->mCurrentPost.setContent( body );
280 d->isPostContentModified =
false;
287 return d->mCurrentPostBlogId;
292 d->mCurrentPostBlogId = blog_id;
293 if ( blog_id != -1 &&
DBMan::self()->blogList().contains( blog_id ) ) {
298 void PostEntry::setCurrentPostFromEditor()
300 if ( d->isPostContentModified ) {
303 d->mCurrentPost.setContent( str );
304 d->isPostContentModified =
false;
311 setCurrentPostFromEditor();
312 return &d->mCurrentPost;
317 d->mCurrentPost = post;
318 kDebug()<<
"local_id: "<<d->mCurrentPost.localId();
319 this->
setPostBody( d->mCurrentPost.content(), d->mCurrentPost.additionalContent() );
325 return d->txtTitle->layoutDirection();
331 d->tabWidget->setLayoutDirection( direction );
332 d->txtTitle->setLayoutDirection( direction );
337 return d->wysiwygEditor->editor()->getLocalImages();
342 d->wysiwygEditor->editor()->replaceImageSrc(src, dest);
347 bool localBackend =
false;
351 backend =
new Backend( d->mCurrentPostBlogId,
this );
358 for ( ; it != endIt; ++it ) {
365 const QString err = i18n(
"Uploading the media file %1 failed.\n%2",
382 const QString err = i18n(
"An error occurred in the last transaction.\n%1", errMsg );
390 setCurrentPostFromEditor();
391 if ( d->mCurrentPost.content().isEmpty() || d->mCurrentPost.title().isEmpty() ) {
392 if ( KMessageBox::warningContinueCancel(
this,
393 i18n(
"Your post title or body is empty.\nAre you sure you want to submit this post?" )
394 ) == KMessageBox::Cancel )
398 if (d->mCurrentPost.status() == BilboPost::New)
401 dia->setAttribute(Qt::WA_DeleteOnClose,
false);
402 if ( dia->exec() == KDialog::Accepted ) {
404 d->mCurrentPost.setProperties( postData );
405 d->mCurrentPostBlogId = blogId;
408 if (dia->isPrivate()) {
409 msgType = i18nc(
"Post status, e.g Draft or Published Post",
"draft");
410 d->mCurrentPost.setPrivate(
true);
412 msgType = i18nc(
"Post status, e.g Draft or Published Post",
"post");
413 d->mCurrentPost.setPrivate(
false);
418 statusMsg = i18n(
"Submitting new %1...", msgType);
421 statusMsg = i18n(
"Modifying %1...", msgType);
422 d->isNewPost =
false;
429 kDebug()<<
"Uploading";
446 kDebug() <<
"BlogId: " << blog_id <<
"Post Id on server: " << post->postId();
450 if ( d->mCurrentPost.isPrivate() ) {
451 msg = i18n(
"Draft with title \"%1\" saved successfully.", post->title() );
452 }
else if (d->mCurrentPost.status() == BilboPost::Modified){
453 msg = i18n(
"Post with title \"%1\" modified successfully.", post->title() );
455 msg = i18n(
"Post with title \"%1\" published successfully.", post->title() );
466 if ( !d->progress ) {
469 d->progress->setRange( 0, 0 );
477 d->progress->deleteLater();
485 if ( KMessageBox::warningYesNo(
this, i18n(
"The current post content is empty, are you sure you want to save an empty post?")) == KMessageBox::No )
490 KMessageBox::detailedSorry(
this, i18n(
"Saving post locally failed."),
DBMan::self()->lastErrorText());
493 d->mCurrentPost.setLocalId( resId );
496 kDebug()<<
"Locally saved";
501 if ( d->isPostContentModified ) {
504 d->mCurrentPost.setLocalId( res );
506 kDebug()<<
"Temporary saved";
519 d->isPostContentModified =
true;
void showStatusMessage(const QString &message, bool isPermanent)
To show a message on statusBar.
static HtmlEditor * self()
void postTitleChanged(const QString &title)
emitted when title of this entry changed.
QString lastErrorText() const
void postPublishingDone(bool isError, const QString &customMessage)
This signal emitted when a post manipulation job e.g.
void replaceImageSrc(const QString &src, const QString &dest)
void slotSyncEditors(int index)
void submitPost(int blogId, const BilboPost &postData)
void publishPost(BilboPost *post)
Use this to publish a post to server.
QString htmlContent() const
Returns the editor current text in html format Synchronizes HtmlEditor and editor tabs...
void setHtmlContent(const QString &content)
Sets the given string as the HtmlEditor and VisualEditor content.
int saveTempEntry(const BilboPost &post, int blog_id)
static DBMan * self()
Retrieve the instance of DataBase Manager.
Qt::LayoutDirection defaultLayoutDirection() const
Definition of a blog post! it's implemented to decrease dependency to KBlog :)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString errorMessage() const
int saveLocalEntry(const BilboPost &post, int blog_id)
void setPostTitle(const QString &title)
void slotSetPostPreview()
QString plainTextContent() const
void slotError(const QString &errMsg)
void setDefaultLayoutDirection(Qt::LayoutDirection direction)
void textChanged()
This signal is emitted when the content of VisualEditor or HtmlEditor changes.
void modifyPost(BilboPost *post)
Modify an existing post.
KTextEditor::View * createView(QWidget *parent)
bool removeTempEntry(const BilboPost &post)
void slotPostPublished(int blog_id, BilboPost *post)
void postSavedTemporary()
This signal is emitted when the post is saved temporarily!
bool uploadMedia(Backend *backend, BilboMedia *media)
Synchronous Media file uploader!
int currentPostBlogId() const
bool uploadMediaFiles(Backend *backend=0)
Will Upload media files not uploaded yet, and return true on success and false on failure...
PostEntry(QWidget *parent)
void setPostBody(const QString &content, const QString &additionalContent=QString())
BilboPost * currentPost()
QList< BilboMedia * > localImages() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setCurrentPost(const BilboPost &post)
Implements a simple browser widget for use in blogilo Post Preview.
QString postTitle() const
void setCurrentPostBlogId(int blog_id)