Improvements to WikiEditDialog

- Make Details togglable
 - Keep track of Modified state.
 - Add peg-markdown Renderer (disabled until I sort out support library).
 - Fix up Submit to submit correct text and handle Utf8



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5925 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-12-01 22:53:50 +00:00
parent c955e3b5a4
commit e1423919aa
3 changed files with 232 additions and 71 deletions

View File

@ -26,6 +26,12 @@
#include <iostream> #include <iostream>
//#define USE_PEGMMD_RENDERER 1
#ifdef USE_PEGMMD_RENDERER
#include "markdown_lib.h"
#endif
#define WIKIEDITDIALOG_GROUP 0x0001 #define WIKIEDITDIALOG_GROUP 0x0001
#define WIKIEDITDIALOG_PAGE 0x0002 #define WIKIEDITDIALOG_PAGE 0x0002
@ -43,14 +49,68 @@ WikiEditDialog::WikiEditDialog(QWidget *parent)
connect(ui.pushButton_Submit, SIGNAL( clicked( void ) ), this, SLOT( submitEdit( void ) ) ); connect(ui.pushButton_Submit, SIGNAL( clicked( void ) ), this, SLOT( submitEdit( void ) ) );
connect(ui.pushButton_Preview, SIGNAL( clicked( void ) ), this, SLOT( previewToggle( void ) ) ); connect(ui.pushButton_Preview, SIGNAL( clicked( void ) ), this, SLOT( previewToggle( void ) ) );
connect(ui.pushButton_History, SIGNAL( clicked( void ) ), this, SLOT( historyToggle( void ) ) ); connect(ui.pushButton_History, SIGNAL( clicked( void ) ), this, SLOT( historyToggle( void ) ) );
connect(ui.toolButton_Show, SIGNAL( clicked( void ) ), this, SLOT( detailsToggle( void ) ) );
connect(ui.toolButton_Hide, SIGNAL( clicked( void ) ), this, SLOT( detailsToggle( void ) ) );
connect(ui.textEdit, SIGNAL( textChanged( void ) ), this, SLOT( textChanged( void ) ) );
mWikiQueue = new TokenQueue(rsWiki->getTokenService(), this); mWikiQueue = new TokenQueue(rsWiki->getTokenService(), this);
mRepublishMode = false; mRepublishMode = false;
mPreviewMode = false; mPreviewMode = false;
mPageLoading = false; mPageLoading = false;
mTextChanged = false;
mCurrentText = ""; mCurrentText = "";
ui.groupBox_History->hide(); ui.groupBox_History->hide();
detailsToggle();
}
void WikiEditDialog::textChanged()
{
mTextChanged = true;
ui.pushButton_Revert->setEnabled(true);
ui.pushButton_Submit->setEnabled(true);
ui.label_Status->setText("Modified");
}
void WikiEditDialog::textReset()
{
mTextChanged = false;
ui.pushButton_Revert->setEnabled(false);
ui.pushButton_Submit->setEnabled(false);
ui.label_Status->setText("Original");
}
void WikiEditDialog::detailsToggle()
{
std::cerr << "WikiEditDialog::detailsToggle()";
std::cerr << std::endl;
if (ui.toolButton_Hide->isHidden())
{
ui.toolButton_Hide->show();
ui.toolButton_Show->hide();
ui.label_PrevVersion->show();
ui.label_Group->show();
ui.label_Tags->show();
ui.lineEdit_PrevVersion->show();
ui.lineEdit_Group->show();
ui.lineEdit_Tags->show();
}
else
{
ui.toolButton_Hide->hide();
ui.toolButton_Show->show();
ui.label_PrevVersion->hide();
ui.label_Group->hide();
ui.label_Tags->hide();
ui.lineEdit_PrevVersion->hide();
ui.lineEdit_Group->hide();
ui.lineEdit_Tags->hide();
}
} }
void WikiEditDialog::historyToggle() void WikiEditDialog::historyToggle()
@ -101,10 +161,25 @@ void WikiEditDialog::redrawPage()
if (mPreviewMode) if (mPreviewMode)
{ {
#ifdef USE_PEGMMD_RENDERER
/* render as HTML */ /* render as HTML */
QString renderedText = "RENDERED TEXT:\n"; QByteArray byte_array = mCurrentText.toUtf8();
int extensions = 0;
char *answer = markdown_to_string(byte_array.data(), extensions, HTML_FORMAT);
QString renderedText = QString::fromUtf8(answer);
ui.textEdit->setHtml(renderedText);
// free answer.
free(answer);
#else
/* render as HTML */
QString renderedText = "IN (dummy) RENDERED TEXT MODE:\n";
renderedText += mCurrentText; renderedText += mCurrentText;
ui.textEdit->setPlainText(renderedText); ui.textEdit->setPlainText(renderedText);
#endif
/* disable edit */ /* disable edit */
ui.textEdit->setReadOnly(true); ui.textEdit->setReadOnly(true);
@ -143,6 +218,7 @@ void WikiEditDialog::setPreviousPage(RsWikiSnapshot &page)
ui.lineEdit_PrevVersion->setText(QString::fromStdString(mWikiSnapshot.mMeta.mMsgId)); ui.lineEdit_PrevVersion->setText(QString::fromStdString(mWikiSnapshot.mMeta.mMsgId));
mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str()); mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str());
redrawPage(); redrawPage();
textReset();
} }
@ -163,6 +239,7 @@ void WikiEditDialog::setNewPage()
ui.headerFrame->setHeaderText(tr("Create New Wiki Page")); ui.headerFrame->setHeaderText(tr("Create New Wiki Page"));
setWindowTitle(tr("Create New Wiki Page")); setWindowTitle(tr("Create New Wiki Page"));
textReset();
} }
@ -192,6 +269,7 @@ void WikiEditDialog::revertEdit()
mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str()); mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str());
} }
redrawPage(); redrawPage();
textReset();
} }
@ -255,7 +333,18 @@ void WikiEditDialog::submitEdit()
mWikiSnapshot.mMeta.mMsgName = ui.lineEdit_Page->text().toStdString(); mWikiSnapshot.mMeta.mMsgName = ui.lineEdit_Page->text().toStdString();
mWikiSnapshot.mPage = ui.textEdit->toPlainText().toStdString();
if (!mPreviewMode)
{
/* can just use the current text */
mCurrentText = ui.textEdit->toPlainText();
}
{
// complicated way of preserving Utf8 text */
QByteArray byte_array = mCurrentText.toUtf8();
mWikiSnapshot.mPage = std::string(byte_array.data());
}
std::cerr << "WikiEditDialog::submitEdit() PageTitle: " << mWikiSnapshot.mMeta.mMsgName; std::cerr << "WikiEditDialog::submitEdit() PageTitle: " << mWikiSnapshot.mMeta.mMsgName;
std::cerr << std::endl; std::cerr << std::endl;

View File

@ -50,6 +50,9 @@ void revertEdit();
void submitEdit(); void submitEdit();
void previewToggle(); void previewToggle();
void historyToggle(); void historyToggle();
void detailsToggle();
void textChanged();
void textReset();
private: private:
@ -76,6 +79,7 @@ void loadEditTreeData(const uint32_t &token);
bool mPageLoading; bool mPageLoading;
bool mRepublishMode; bool mRepublishMode;
bool mTextChanged;
QString mCurrentText; QString mCurrentText;

View File

@ -28,9 +28,6 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<zorder>frame</zorder>
<zorder>frame</zorder>
<zorder>frame</zorder>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
@ -54,12 +51,6 @@
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QGroupBox" name="groupBox_History"> <widget class="QGroupBox" name="groupBox_History">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title"> <property name="title">
<string>Page Edit History</string> <string>Page Edit History</string>
</property> </property>
@ -87,20 +78,65 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0"> <layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,10,0">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="title"> <item>
<string>Wiki Page</string> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QToolButton" name="toolButton_Show">
<property name="text">
<string>\/</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="toolButton_Hide">
<property name="text">
<string>/\</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_Group">
<property name="text"> <property name="text">
<string>Wiki Group:</string> <string>Wiki Group:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>groupBox</cstring> <cstring>frame</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -112,7 +148,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label_Page">
<property name="text"> <property name="text">
<string>Page Name:</string> <string>Page Name:</string>
</property> </property>
@ -129,7 +165,7 @@
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_PrevVersion">
<property name="text"> <property name="text">
<string>Previous Version</string> <string>Previous Version</string>
</property> </property>
@ -148,9 +184,34 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="label_Tags">
<property name="text">
<string>Tags</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_Tags">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
@ -173,6 +234,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QLabel" name="label_Status">
<property name="text">
<string>Status</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="pushButton_Preview"> <widget class="QPushButton" name="pushButton_Preview">
<property name="text"> <property name="text">