More improvements to Wiki, mainly EditMode.

- Fixed display of Edit History. (Date, Author, PageId)
 - Added GxsId for Author Display.
 - Enabled/Disabled History depending on Modification & oldHistory flags.
 - Fixed bug where preview triggered Modification Flag.
 - Switched WikiDialog to Rendered Mode, and removed spacer.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5929 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-12-02 19:06:43 +00:00
parent bcd67a8651
commit 083c4411b8
5 changed files with 221 additions and 42 deletions

View File

@ -28,7 +28,7 @@
#include "gui/WikiPoos/WikiAddDialog.h" #include "gui/WikiPoos/WikiAddDialog.h"
#include "gui/WikiPoos/WikiEditDialog.h" #include "gui/WikiPoos/WikiEditDialog.h"
#include "gui/gxs/WikiGroupDialog.h" #include "gui/gxs/WikiGroupDialog.h"
#include <retroshare/rswiki.h> #include <retroshare/rswiki.h>
@ -37,6 +37,12 @@
#include <QTimer> #include <QTimer>
//#define USE_PEGMMD_RENDERER 1
#ifdef USE_PEGMMD_RENDERER
#include "markdown_lib.h"
#endif
/****** /******
* #define WIKI_DEBUG 1 * #define WIKI_DEBUG 1
*****/ *****/
@ -318,7 +324,22 @@ void WikiDialog::modTreeChanged()
void WikiDialog::updateWikiPage(const RsWikiSnapshot &page) void WikiDialog::updateWikiPage(const RsWikiSnapshot &page)
{ {
ui.textBrowser->setPlainText(QString::fromStdString(page.mPage)); #ifdef USE_PEGMMD_RENDERER
/* render as HTML */
int extensions = 0;
char *answer = markdown_to_string((char *) page.mPage.c_str(), extensions, HTML_FORMAT);
QString renderedText = QString::fromUtf8(answer);
ui.textBrowser->setHtml(renderedText);
// free answer.
free(answer);
#else
/* render as HTML */
QString renderedText = "IN (dummy) RENDERED TEXT MODE:\n";
renderedText += QString::fromStdString(page.mPage);
ui.textBrowser->setPlainText(renderedText);
#endif
} }

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>902</width> <width>918</width>
<height>669</height> <height>669</height>
</rect> </rect>
</property> </property>
@ -109,8 +109,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>271</width> <width>241</width>
<height>302</height> <height>307</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -154,8 +154,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>271</width> <width>241</width>
<height>302</height> <height>294</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
@ -436,8 +436,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>645</width>
<height>611</height> <height>609</height>
</rect> </rect>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
@ -455,22 +455,6 @@
<item> <item>
<widget class="QTextBrowser" name="textBrowser"/> <widget class="QTextBrowser" name="textBrowser"/>
</item> </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>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -21,7 +21,9 @@
* *
*/ */
#include <QDateTime>
#include "gui/gxs/GxsIdTreeWidgetItem.h"
#include "gui/WikiPoos/WikiEditDialog.h" #include "gui/WikiPoos/WikiEditDialog.h"
#include <iostream> #include <iostream>
@ -36,7 +38,21 @@
#define WIKIEDITDIALOG_GROUP 0x0001 #define WIKIEDITDIALOG_GROUP 0x0001
#define WIKIEDITDIALOG_PAGE 0x0002 #define WIKIEDITDIALOG_PAGE 0x0002
#define WIKIEDITDIALOG_BASEHISTORY 0x0003 #define WIKIEDITDIALOG_BASEHISTORY 0x0003
#define WIKIEDITDIALOG_EDITTREE 0x0005 #define WIKIEDITDIALOG_EDITTREE 0x0004
#define WET_COL_DATE 0
#define WET_COL_AUTHORID 1
#define WET_COL_PAGEID 2
#define WET_DATA_COLUMN 0
#define WET_ROLE_ORIGPAGEID Qt::UserRole
#define WET_ROLE_PAGEID Qt::UserRole + 1
#define WET_ROLE_PARENTID Qt::UserRole + 2
#define WET_ROLE_SORT Qt::UserRole + 3
/** Constructor */ /** Constructor */
WikiEditDialog::WikiEditDialog(QWidget *parent) WikiEditDialog::WikiEditDialog(QWidget *parent)
@ -52,36 +68,126 @@ WikiEditDialog::WikiEditDialog(QWidget *parent)
connect(ui.toolButton_Show, SIGNAL( clicked( void ) ), this, SLOT( detailsToggle( 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.toolButton_Hide, SIGNAL( clicked( void ) ), this, SLOT( detailsToggle( void ) ) );
connect(ui.textEdit, SIGNAL( textChanged( void ) ), this, SLOT( textChanged( void ) ) ); connect(ui.textEdit, SIGNAL( textChanged( void ) ), this, SLOT( textChanged( void ) ) );
connect(ui.checkBox_OldHistory, SIGNAL( clicked( void ) ), this, SLOT( oldHistoryChanged( void ) ) );
connect(ui.treeWidget_History, SIGNAL( itemSelectionChanged( void ) ), this, SLOT( historySelected( void ) ) );
mWikiQueue = new TokenQueue(rsWiki->getTokenService(), this); mWikiQueue = new TokenQueue(rsWiki->getTokenService(), this);
mThreadCompareRole = new RSTreeWidgetItemCompareRole;
mThreadCompareRole->setRole(WET_COL_DATE, WET_ROLE_SORT);
mRepublishMode = false; mRepublishMode = false;
mPreviewMode = false; mPreviewMode = false;
mPageLoading = false; mPageLoading = false;
mTextChanged = false; mTextChanged = false;
mCurrentText = ""; mCurrentText = "";
ui.checkBox_OldHistory->setChecked(false);
mOldHistoryEnabled = false;
ui.groupBox_History->hide(); ui.groupBox_History->hide();
detailsToggle(); detailsToggle();
} }
WikiEditDialog::~WikiEditDialog()
{
delete (mThreadCompareRole);
}
void WikiEditDialog::textChanged() void WikiEditDialog::textChanged()
{ {
std::cerr << "WikiEditDialog::textChanged()" << std::endl;
mTextChanged = true; mTextChanged = true;
ui.pushButton_Revert->setEnabled(true); ui.pushButton_Revert->setEnabled(true);
ui.pushButton_Submit->setEnabled(true); ui.pushButton_Submit->setEnabled(true);
ui.label_Status->setText("Modified"); ui.label_Status->setText("Modified");
// Disable Selection in Edit History.
ui.treeWidget_History->setSelectionMode(QAbstractItemView::NoSelection);
updateHistoryStatus();
// unselect anything.
} }
void WikiEditDialog::textReset() void WikiEditDialog::textReset()
{ {
std::cerr << "WikiEditDialog::textReset()" << std::endl;
mTextChanged = false; mTextChanged = false;
ui.pushButton_Revert->setEnabled(false); ui.pushButton_Revert->setEnabled(false);
ui.pushButton_Submit->setEnabled(false); ui.pushButton_Submit->setEnabled(false);
ui.label_Status->setText("Original"); ui.label_Status->setText("Original");
// Enable Selection in Edit History.
ui.treeWidget_History->setSelectionMode(QAbstractItemView::SingleSelection);
updateHistoryStatus();
}
void WikiEditDialog::historySelected()
{
std::cerr << "WikiEditDialog::historySelected()" << std::endl;
} }
void WikiEditDialog::oldHistoryChanged()
{
mOldHistoryEnabled = ui.checkBox_OldHistory->isChecked();
updateHistoryStatus();
}
void WikiEditDialog::updateHistoryStatus()
{
/* iterate through every History Item */
int count = ui.treeWidget_History->topLevelItemCount();
for(int i = 0; i < count; i++)
{
QTreeWidgetItem *item = ui.treeWidget_History->topLevelItem(i);
bool isLatest = (i==count-1);
updateHistoryChildren(item, isLatest);
updateHistoryItem(item, isLatest);
}
}
void WikiEditDialog::updateHistoryChildren(QTreeWidgetItem *item, bool isLatest)
{
int count = item->childCount();
for(int i = 0; i < count; i++)
{
QTreeWidgetItem *child = item->child(i);
if (child->childCount() > 0)
{
updateHistoryChildren(child, isLatest);
}
updateHistoryItem(child, isLatest);
}
}
void WikiEditDialog::updateHistoryItem(QTreeWidgetItem *item, bool isLatest)
{
bool isSelectable = true;
if (mTextChanged)
{
isSelectable = false;
}
else if ((!mOldHistoryEnabled) && (!isLatest))
{
isSelectable = false;
}
if (isSelectable)
{
item->setFlags(Qt::ItemIsSelectable |
Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
}
else
{
item->setFlags(0);
}
}
void WikiEditDialog::detailsToggle() void WikiEditDialog::detailsToggle()
{ {
@ -135,6 +241,8 @@ void WikiEditDialog::previewToggle()
std::cerr << "WikiEditDialog::previewToggle()"; std::cerr << "WikiEditDialog::previewToggle()";
std::cerr << std::endl; std::cerr << std::endl;
bool prevTextChanged = mTextChanged;
if (mPreviewMode) if (mPreviewMode)
{ {
mPreviewMode = false; mPreviewMode = false;
@ -151,6 +259,15 @@ void WikiEditDialog::previewToggle()
{ {
redrawPage(); redrawPage();
} }
/* fix textChanged signal - if we have caused it to change */
if (!prevTextChanged)
{
textReset();
}
std::cerr << "WikiEditDialog::previewToggle() END";
std::cerr << std::endl;
} }
@ -475,10 +592,6 @@ void WikiEditDialog::loadPage(const uint32_t &token)
/*********************** LOAD EDIT HISTORY **********************/ /*********************** LOAD EDIT HISTORY **********************/
#define WIKIEDITTREE_COL_ORIGPAGEID 0
#define WIKIEDITTREE_COL_PAGEID 1
#define WIKIEDITTREE_COL_PARENTID 2
void WikiEditDialog::requestBaseHistory(const RsGxsGrpMsgIdPair &origMsgId) void WikiEditDialog::requestBaseHistory(const RsGxsGrpMsgIdPair &origMsgId)
{ {
RsTokReqOptions opts; RsTokReqOptions opts;
@ -521,10 +634,27 @@ void WikiEditDialog::loadBaseHistory(const uint32_t &token)
std::cerr << " ParentId: " << page.mMeta.mParentId; std::cerr << " ParentId: " << page.mMeta.mParentId;
std::cerr << std::endl; std::cerr << std::endl;
QTreeWidgetItem *modItem = new QTreeWidgetItem(); GxsIdTreeWidgetItem *modItem = new GxsIdTreeWidgetItem(mThreadCompareRole);
modItem->setText(WIKIEDITTREE_COL_ORIGPAGEID, QString::fromStdString(page.mMeta.mOrigMsgId)); modItem->setData(WET_DATA_COLUMN, WET_ROLE_ORIGPAGEID, QString::fromStdString(page.mMeta.mOrigMsgId));
modItem->setText(WIKIEDITTREE_COL_PAGEID, QString::fromStdString(page.mMeta.mMsgId)); modItem->setData(WET_DATA_COLUMN, WET_ROLE_PAGEID, QString::fromStdString(page.mMeta.mMsgId));
modItem->setText(WIKIEDITTREE_COL_PARENTID, QString::fromStdString(page.mMeta.mParentId));
modItem->setData(WET_DATA_COLUMN, WET_ROLE_PARENTID, QString::fromStdString(page.mMeta.mParentId));
{
// From Forum stuff.
QDateTime qtime;
QString text;
QString sort;
qtime.setTime_t(page.mMeta.mPublishTs);
sort = qtime.toString("yyyyMMdd_hhmmss");
text = qtime.toString("dd/MM/yy hh:mm");
modItem->setText(WET_COL_DATE, text);
modItem->setData(WET_COL_DATE, WET_ROLE_SORT, sort);
}
modItem->setId(page.mMeta.mAuthorId, WET_COL_AUTHORID);
modItem->setText(WET_COL_PAGEID, QString::fromStdString(page.mMeta.mMsgId));
ui.treeWidget_History->addTopLevelItem(modItem); ui.treeWidget_History->addTopLevelItem(modItem);
} }
@ -583,7 +713,7 @@ void WikiEditDialog::loadEditTreeData(const uint32_t &token)
QTreeWidgetItem *item = ui.treeWidget_History->topLevelItem(nIndex); QTreeWidgetItem *item = ui.treeWidget_History->topLevelItem(nIndex);
/* index by MsgId --> ONLY For Wiki Thread Head Items... SPECIAL HACK FOR HERE! */ /* index by MsgId --> ONLY For Wiki Thread Head Items... SPECIAL HACK FOR HERE! */
std::string msgId = item->text(WIKIEDITTREE_COL_PAGEID).toStdString(); std::string msgId = item->data(WET_DATA_COLUMN, WET_ROLE_PAGEID).toString().toStdString();
items[msgId] = item; items[msgId] = item;
} }
@ -619,10 +749,25 @@ void WikiEditDialog::loadEditTreeData(const uint32_t &token)
} }
/* create an Entry */ /* create an Entry */
QTreeWidgetItem *modItem = new QTreeWidgetItem(); GxsIdTreeWidgetItem *modItem = new GxsIdTreeWidgetItem(mThreadCompareRole);
modItem->setText(WIKIEDITTREE_COL_ORIGPAGEID, QString::fromStdString(snapshot.mMeta.mOrigMsgId)); modItem->setData(WET_DATA_COLUMN, WET_ROLE_ORIGPAGEID, QString::fromStdString(snapshot.mMeta.mOrigMsgId));
modItem->setText(WIKIEDITTREE_COL_PAGEID, QString::fromStdString(snapshot.mMeta.mMsgId)); modItem->setData(WET_DATA_COLUMN, WET_ROLE_PAGEID, QString::fromStdString(snapshot.mMeta.mMsgId));
modItem->setText(WIKIEDITTREE_COL_PARENTID, QString::fromStdString(snapshot.mMeta.mParentId)); modItem->setData(WET_DATA_COLUMN, WET_ROLE_PARENTID, QString::fromStdString(snapshot.mMeta.mParentId));
{
// From Forum stuff.
QDateTime qtime;
QString text;
QString sort;
qtime.setTime_t(snapshot.mMeta.mPublishTs);
sort = qtime.toString("yyyyMMdd_hhmmss");
text = qtime.toString("dd/MM/yy hh:mm");
modItem->setText(WET_COL_DATE, text);
modItem->setData(WET_COL_DATE, WET_ROLE_SORT, sort);
}
modItem->setId(snapshot.mMeta.mAuthorId, WET_COL_AUTHORID);
modItem->setText(WET_COL_PAGEID, QString::fromStdString(snapshot.mMeta.mMsgId));
/* find the parent */ /* find the parent */
iit = items.find(snapshot.mMeta.mParentId); iit = items.find(snapshot.mMeta.mParentId);
@ -639,7 +784,8 @@ void WikiEditDialog::loadEditTreeData(const uint32_t &token)
for(uit = unparented.begin(); uit != unparented.end(); uit++) for(uit = unparented.begin(); uit != unparented.end(); uit++)
{ {
std::string parentId = (*uit)->text(WIKIEDITTREE_COL_PARENTID).toStdString(); std::string parentId = (*uit)->data(WET_DATA_COLUMN, WET_ROLE_PARENTID).toString().toStdString();
iit = items.find(parentId); iit = items.find(parentId);
if (iit != items.end()) if (iit != items.end())
@ -653,6 +799,9 @@ void WikiEditDialog::loadEditTreeData(const uint32_t &token)
std::cerr << std::endl; std::cerr << std::endl;
} }
} }
// Enable / Disable Items.
updateHistoryStatus();
} }

View File

@ -29,12 +29,15 @@
#include <retroshare/rswiki.h> #include <retroshare/rswiki.h>
#include "util/TokenQueue.h" #include "util/TokenQueue.h"
class RSTreeWidgetItemCompareRole;
class WikiEditDialog : public QWidget, public TokenResponse class WikiEditDialog : public QWidget, public TokenResponse
{ {
Q_OBJECT Q_OBJECT
public: public:
WikiEditDialog(QWidget *parent = 0); WikiEditDialog(QWidget *parent = 0);
~WikiEditDialog();
void setNewPage(); void setNewPage();
@ -54,8 +57,15 @@ void detailsToggle();
void textChanged(); void textChanged();
void textReset(); void textReset();
void historySelected();
void oldHistoryChanged();
private: private:
void updateHistoryStatus();
void updateHistoryChildren(QTreeWidgetItem *item, bool isLatest);
void updateHistoryItem(QTreeWidgetItem *item, bool isLatest);
void redrawPage(); void redrawPage();
void setGroup(RsWikiCollection &group); void setGroup(RsWikiCollection &group);
@ -77,6 +87,7 @@ void loadEditTreeData(const uint32_t &token);
bool mPreviewMode; bool mPreviewMode;
bool mPageLoading; bool mPageLoading;
bool mOldHistoryEnabled;
bool mRepublishMode; bool mRepublishMode;
bool mTextChanged; bool mTextChanged;
@ -91,6 +102,8 @@ void loadEditTreeData(const uint32_t &token);
Ui::WikiEditDialog ui; Ui::WikiEditDialog ui;
RSTreeWidgetItemCompareRole *mThreadCompareRole;
TokenQueue *mWikiQueue; TokenQueue *mWikiQueue;
}; };

View File

@ -54,9 +54,21 @@
<property name="title"> <property name="title">
<string>Page Edit History</string> <string>Page Edit History</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0"> <layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0">
<item>
<widget class="QCheckBox" name="checkBox_OldHistory">
<property name="text">
<string>Enable Obsolete Edits</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QTreeWidget" name="treeWidget_History"> <widget class="QTreeWidget" name="treeWidget_History">
<column>
<property name="text">
<string>Publish Date</string>
</property>
</column>
<column> <column>
<property name="text"> <property name="text">
<string>By</string> <string>By</string>
@ -64,7 +76,7 @@
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>When</string> <string>PageId</string>
</property> </property>
</column> </column>
</widget> </widget>