Reworked Wiki Edit Dialog.

- Added EditHistory SideBar (Will remove from main page).
 - Added Preview / Edit modes. (to add renderer)
 - changed layout a bit.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5923 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-12-01 17:23:25 +00:00
parent 30ea727333
commit c955e3b5a4
3 changed files with 529 additions and 170 deletions

View File

@ -26,22 +26,100 @@
#include <iostream>
#define WIKIEDITDIALOG_GROUP 0x0001
#define WIKIEDITDIALOG_PAGE 0x0002
#define WIKIEDITDIALOG_BASEHISTORY 0x0003
#define WIKIEDITDIALOG_EDITTREE 0x0005
/** Constructor */
WikiEditDialog::WikiEditDialog(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
ui.setupUi(this);
connect(ui.pushButton_Cancel, SIGNAL( clicked( void ) ), this, SLOT( cancelEdit( void ) ) );
connect(ui.pushButton_Revert, SIGNAL( clicked( void ) ), this, SLOT( revertEdit( 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_History, SIGNAL( clicked( void ) ), this, SLOT( historyToggle( void ) ) );
mWikiQueue = new TokenQueue(rsWiki->getTokenService(), this);
mRepublishMode = false;
mPreviewMode = false;
mPageLoading = false;
mCurrentText = "";
ui.groupBox_History->hide();
}
void WikiEditDialog::historyToggle()
{
std::cerr << "WikiEditDialog::historyToggle()";
std::cerr << std::endl;
if (ui.groupBox_History->isHidden())
{
ui.groupBox_History->show();
ui.pushButton_History->setText(tr("Hide Edit History"));
}
else
{
ui.groupBox_History->hide();
ui.pushButton_History->setText(tr("Show Edit History"));
}
}
void WikiEditDialog::previewToggle()
{
std::cerr << "WikiEditDialog::previewToggle()";
std::cerr << std::endl;
if (mPreviewMode)
{
mPreviewMode = false;
ui.pushButton_Preview->setText(tr("Preview"));
}
else
{
// Save existing Text into buffer.
mCurrentText = ui.textEdit->toPlainText();
mPreviewMode = true;
ui.pushButton_Preview->setText(tr("Edit Page"));
}
if (!mPageLoading)
{
redrawPage();
}
}
void WikiEditDialog::redrawPage()
{
std::cerr << "WikiEditDialog::redrawPage()";
std::cerr << std::endl;
if (mPreviewMode)
{
/* render as HTML */
QString renderedText = "RENDERED TEXT:\n";
renderedText += mCurrentText;
ui.textEdit->setPlainText(renderedText);
/* disable edit */
ui.textEdit->setReadOnly(true);
}
else
{
/* plain text - for editing */
ui.textEdit->setPlainText(mCurrentText);
/* enable edit */
ui.textEdit->setReadOnly(false);
}
}
void WikiEditDialog::setGroup(RsWikiCollection &group)
{
std::cerr << "WikiEditDialog::setGroup(): " << group;
@ -63,7 +141,8 @@ void WikiEditDialog::setPreviousPage(RsWikiSnapshot &page)
ui.lineEdit_Page->setText(QString::fromStdString(mWikiSnapshot.mMeta.mMsgName));
ui.lineEdit_PrevVersion->setText(QString::fromStdString(mWikiSnapshot.mMeta.mMsgId));
ui.textEdit->setPlainText(QString::fromStdString(mWikiSnapshot.mPage));
mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str());
redrawPage();
}
@ -73,11 +152,17 @@ void WikiEditDialog::setNewPage()
mRepublishMode = false;
ui.lineEdit_Page->setText("");
ui.lineEdit_PrevVersion->setText("");
ui.textEdit->setPlainText("");
mCurrentText = "";
redrawPage();
ui.treeWidget_History->clear();
ui.groupBox_History->hide();
ui.pushButton_History->setText(tr("Show Edit History"));
ui.headerFrame->setHeaderImage(QPixmap(":/images/appointment-new_64.png"));
ui.headerFrame->setHeaderText(tr("Create New Wiki Page"));
setWindowTitle(tr("Create New Wiki Page"));
ui.headerFrame->setHeaderText(tr("Create New Wiki Page"));
setWindowTitle(tr("Create New Wiki Page"));
}
@ -99,12 +184,14 @@ void WikiEditDialog::revertEdit()
{
if (mNewPage)
{
ui.textEdit->setPlainText("");
mCurrentText = "";
}
else
{
ui.textEdit->setPlainText(QString::fromStdString(mWikiSnapshot.mPage));
mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str());
}
redrawPage();
}
@ -224,7 +311,7 @@ void WikiEditDialog::requestGroup(const std::string &groupId)
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mWikiQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids, 0);
mWikiQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids, WIKIEDITDIALOG_GROUP);
}
void WikiEditDialog::loadGroup(const uint32_t &token)
@ -258,7 +345,8 @@ void WikiEditDialog::requestPage(const RsGxsGrpMsgIdPair &msgId)
vect_msgIds.push_back(msgId.second);
uint32_t token;
mWikiQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, 0);
mWikiQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, WIKIEDITDIALOG_PAGE);
mPageLoading = true;
}
void WikiEditDialog::loadPage(const uint32_t &token)
@ -276,10 +364,210 @@ void WikiEditDialog::loadPage(const uint32_t &token)
std::cerr << std::endl;
return;
}
setPreviousPage(snapshots[0]);
RsWikiSnapshot &page = snapshots[0];
setPreviousPage(page);
/* request the history now */
mThreadMsgIdPair.first = page.mMeta.mGroupId;
if (page.mMeta.mThreadId.empty())
{
mThreadMsgIdPair.second = page.mMeta.mOrigMsgId;
}
else
{
mThreadMsgIdPair.second = page.mMeta.mThreadId;
}
requestBaseHistory(mThreadMsgIdPair);
}
mPageLoading = false;
}
/*********************** LOAD EDIT HISTORY **********************/
#define WIKIEDITTREE_COL_ORIGPAGEID 0
#define WIKIEDITTREE_COL_PAGEID 1
#define WIKIEDITTREE_COL_PARENTID 2
void WikiEditDialog::requestBaseHistory(const RsGxsGrpMsgIdPair &origMsgId)
{
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_VERSIONS;
std::vector<RsGxsGrpMsgIdPair> msgIds;
msgIds.push_back(origMsgId);
uint32_t token;
mWikiQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, WIKIEDITDIALOG_BASEHISTORY);
ui.treeWidget_History->clear();
}
void WikiEditDialog::loadBaseHistory(const uint32_t &token)
{
std::cerr << "WikiEditDialog::loadBaseHistory()";
std::cerr << std::endl;
std::vector<RsWikiSnapshot> snapshots;
std::vector<RsWikiSnapshot>::iterator vit;
if (!rsWiki->getRelatedSnapshots(token, snapshots))
{
// ERROR
std::cerr << "WikiEditDialog::loadBaseHistory() ERROR";
std::cerr << std::endl;
return;
}
for(vit = snapshots.begin(); vit != snapshots.end(); vit++)
{
RsWikiSnapshot &page = *vit;
std::cerr << "WikiEditDialog::loadBaseHistory() TopLevel Result: PageTitle: " << page.mMeta.mMsgName;
std::cerr << " GroupId: " << page.mMeta.mGroupId;
std::cerr << std::endl;
std::cerr << "\tOrigMsgId: " << page.mMeta.mOrigMsgId;
std::cerr << " MsgId: " << page.mMeta.mMsgId;
std::cerr << std::endl;
std::cerr << "\tThreadId: " << page.mMeta.mThreadId;
std::cerr << " ParentId: " << page.mMeta.mParentId;
std::cerr << std::endl;
QTreeWidgetItem *modItem = new QTreeWidgetItem();
modItem->setText(WIKIEDITTREE_COL_ORIGPAGEID, QString::fromStdString(page.mMeta.mOrigMsgId));
modItem->setText(WIKIEDITTREE_COL_PAGEID, QString::fromStdString(page.mMeta.mMsgId));
modItem->setText(WIKIEDITTREE_COL_PARENTID, QString::fromStdString(page.mMeta.mParentId));
ui.treeWidget_History->addTopLevelItem(modItem);
}
/* then we need to request all pages from this thread */
requestEditTreeData();
}
void WikiEditDialog::requestEditTreeData() //const RsGxsGroupId &groupId)
{
// SWITCH THIS TO A THREAD REQUEST - WHEN WE CAN!
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(mThreadMsgIdPair.first);
uint32_t token;
mWikiQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, WIKIEDITDIALOG_EDITTREE);
}
void WikiEditDialog::loadEditTreeData(const uint32_t &token)
{
std::cerr << "WikiEditDialog::loadEditTreeData()";
std::cerr << std::endl;
std::vector<RsWikiSnapshot> snapshots;
std::vector<RsWikiSnapshot>::iterator vit;
if (!rsWiki->getSnapshots(token, snapshots))
{
// ERROR
std::cerr << "WikiEditDialog::loadEditTreeData() ERROR";
std::cerr << std::endl;
return;
}
std::cerr << "WikiEditDialog::loadEditTreeData() Loaded " << snapshots.size();
std::cerr << std::endl;
std::cerr << "WikiEditDialog::loadEditTreeData() Using ThreadId: " << mThreadMsgIdPair.second;
std::cerr << std::endl;
std::map<RsGxsMessageId, QTreeWidgetItem *> items;
std::map<RsGxsMessageId, QTreeWidgetItem *>::iterator iit;
std::list<QTreeWidgetItem *> unparented;
std::list<QTreeWidgetItem *>::iterator uit;
// Grab the existing TopLevelItems, and insert into map.
int itemCount = ui.treeWidget_History->topLevelItemCount();
for (int nIndex = 0; nIndex < itemCount; nIndex++)
{
QTreeWidgetItem *item = ui.treeWidget_History->topLevelItem(nIndex);
/* index by MsgId --> ONLY For Wiki Thread Head Items... SPECIAL HACK FOR HERE! */
std::string msgId = item->text(WIKIEDITTREE_COL_PAGEID).toStdString();
items[msgId] = item;
}
for(vit = snapshots.begin(); vit != snapshots.end(); vit++)
{
RsWikiSnapshot &snapshot = *vit;
std::cerr << "Result: PageTitle: " << snapshot.mMeta.mMsgName;
std::cerr << " GroupId: " << snapshot.mMeta.mGroupId;
std::cerr << std::endl;
std::cerr << "\tOrigMsgId: " << snapshot.mMeta.mOrigMsgId;
std::cerr << " MsgId: " << snapshot.mMeta.mMsgId;
std::cerr << std::endl;
std::cerr << "\tThreadId: " << snapshot.mMeta.mThreadId;
std::cerr << " ParentId: " << snapshot.mMeta.mParentId;
std::cerr << std::endl;
if (snapshot.mMeta.mParentId == "")
{
/* Ignore! */
std::cerr << "Ignoring ThreadHead Item";
std::cerr << std::endl;
continue;
}
if (snapshot.mMeta.mThreadId != mThreadMsgIdPair.second)
{
/* Ignore! */
std::cerr << "Ignoring Different Thread Item";
std::cerr << std::endl;
continue;
}
/* create an Entry */
QTreeWidgetItem *modItem = new QTreeWidgetItem();
modItem->setText(WIKIEDITTREE_COL_ORIGPAGEID, QString::fromStdString(snapshot.mMeta.mOrigMsgId));
modItem->setText(WIKIEDITTREE_COL_PAGEID, QString::fromStdString(snapshot.mMeta.mMsgId));
modItem->setText(WIKIEDITTREE_COL_PARENTID, QString::fromStdString(snapshot.mMeta.mParentId));
/* find the parent */
iit = items.find(snapshot.mMeta.mParentId);
if (iit != items.end())
{
(iit->second)->addChild(modItem);
}
else
{
unparented.push_back(modItem);
}
items[snapshot.mMeta.mOrigMsgId] = modItem;
}
for(uit = unparented.begin(); uit != unparented.end(); uit++)
{
std::string parentId = (*uit)->text(WIKIEDITTREE_COL_PARENTID).toStdString();
iit = items.find(parentId);
if (iit != items.end())
{
(iit->second)->addChild(*uit);
}
else
{
/* ERROR */
std::cerr << "Unparented!!!";
std::cerr << std::endl;
}
}
}
void WikiEditDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
std::cerr << "WikiEditDialog::loadRequest()";
@ -287,19 +575,27 @@ void WikiEditDialog::loadRequest(const TokenQueue *queue, const TokenRequest &re
if (queue == mWikiQueue)
{
/* now switch on req */
switch(req.mType)
switch(req.mUserType)
{
case TOKENREQ_GROUPINFO:
loadGroup(req.mToken);
case WIKIEDITDIALOG_GROUP:
loadGroup(req.mToken);
break;
case WIKIEDITDIALOG_PAGE:
loadPage(req.mToken);
break;
case WIKIEDITDIALOG_BASEHISTORY:
loadBaseHistory(req.mToken);
break;
case WIKIEDITDIALOG_EDITTREE:
loadEditTreeData(req.mToken);
break;
default:
std::cerr << "WikiEditDialog::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
break;
case TOKENREQ_MSGINFO:
loadPage(req.mToken);
break;
default:
std::cerr << "WikiEditDialog::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
break;
}
}
}
@ -307,3 +603,7 @@ void WikiEditDialog::loadRequest(const TokenQueue *queue, const TokenRequest &re

View File

@ -48,9 +48,13 @@ private slots:
void cancelEdit();
void revertEdit();
void submitEdit();
void previewToggle();
void historyToggle();
private:
void redrawPage();
void setGroup(RsWikiCollection &group);
void setPreviousPage(RsWikiSnapshot &page);
@ -59,9 +63,23 @@ void loadPage(const uint32_t &token);
void requestGroup(const std::string &groupId);
void loadGroup(const uint32_t &token);
void requestBaseHistory(const RsGxsGrpMsgIdPair &origMsgId);
void loadBaseHistory(const uint32_t &token);
void requestEditTreeData();
void loadEditTreeData(const uint32_t &token);
bool mNewPage;
bool mPreviewMode;
bool mPageLoading;
bool mRepublishMode;
QString mCurrentText;
RsGxsGrpMsgIdPair mThreadMsgIdPair;
RsGxsMessageId mRepublishOrigId;
RsWikiCollection mWikiCollection;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>647</width>
<height>618</height>
<width>731</width>
<height>701</height>
</rect>
</property>
<property name="windowTitle">
@ -28,6 +28,9 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<zorder>frame</zorder>
<zorder>frame</zorder>
<zorder>frame</zorder>
</widget>
</item>
<item row="1" column="0">
@ -38,154 +41,192 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Wiki Page</string>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QSplitter" name="splitter_History">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Wiki Group:</string>
</property>
<property name="buddy">
<cstring>groupBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_Group">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>168</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Page Name:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_Page">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Edit ID</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QComboBox" name="comboBox_Id"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Previous Version</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_PrevVersion">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Prev ID</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="lineEdit_PrevId">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QGroupBox" name="groupBox_History">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Page Edit History</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0">
<item>
<widget class="QTreeWidget" name="treeWidget_History">
<column>
<property name="text">
<string>By</string>
</property>
</column>
<column>
<property name="text">
<string>When</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QFrame" name="frame_3">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Wiki Page</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Wiki Group:</string>
</property>
<property name="buddy">
<cstring>groupBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_Group">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Page Name:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_Page">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Previous Version</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_PrevVersion">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_History">
<property name="text">
<string>Show Edit History</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>178</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_Preview">
<property name="text">
<string>Preview</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_Cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Revert">
<property name="text">
<string>Revert</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>228</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_Submit">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QTextEdit" name="textEdit"/>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_Cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Revert">
<property name="text">
<string>Revert</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>228</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_Submit">
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>