Improved the notification model so that it uses Qt signals to avoid core dumps, and improved the gui to increase responsiveness (e.g. forum display, network discovery info, friends, msg deletion and selection)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1050 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-02-22 17:36:39 +00:00
parent 93fa052b58
commit 59cdaba9dc
25 changed files with 298 additions and 292 deletions

View file

@ -85,7 +85,7 @@ ForumsDialog::ForumsDialog(QWidget *parent)
// SLOT( changedThread( QTreeWidgetItem *, QTreeWidgetItem * ) ) );
connect( ui.threadTreeWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( changedThread2() ) );
connect( ui.viewBox, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( changedThread2() ) );
connect( ui.viewBox, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( insertThreads() ) );
connect(ui.expandButton, SIGNAL(clicked()), this, SLOT(togglefileview()));

View file

@ -33,11 +33,11 @@ public:
ForumsDialog(QWidget *parent = 0);
void insertForums();
void insertThreads();
void insertPost();
private slots:
void insertThreads();
/** Create the context popup menu and it's submenus */
void forumListCustomPopupMenu( QPoint point );
void threadListCustomPopupMenu( QPoint point );

View file

@ -65,7 +65,7 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect( ui.msgWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messageslistWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.msgList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgfilelistWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.msgWidget, SIGNAL( itemClicked ( QTreeWidgetItem *, int) ), this, SLOT( updateMessages ( QTreeWidgetItem *, int) ) );
connect( ui.msgWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem *,QTreeWidgetItem * ) ), this, SLOT( updateCurrentMessage( QTreeWidgetItem *, QTreeWidgetItem *) ) );
connect( ui.listWidget, SIGNAL( currentRowChanged ( int) ), this, SLOT( changeBox ( int) ) );
connect(ui.newmessageButton, SIGNAL(clicked()), this, SLOT(newmessage()));
@ -448,11 +448,9 @@ void MessagesDialog::getallrecommended()
}
}
void MessagesDialog::changeBox( int newrow )
void MessagesDialog::changeBox(int)
{
//std::cerr << "MessagesDialog::changeBox()" << std::endl;
insertMessages();
insertMsgTxtAndFiles();
insertMessages(); // show current msg list
}
void MessagesDialog::insertMessages()
@ -463,7 +461,7 @@ void MessagesDialog::insertMessages()
rsMsgs -> getMessageSummaries(msgList);
/* get a link to the table */
QTreeWidget *msgWidget = ui.msgWidget;
QTreeWidget *msgWidget = ui.msgWidget;
/* get the MsgId of the current one ... */
@ -500,7 +498,7 @@ void MessagesDialog::insertMessages()
break;
}
QList<QTreeWidgetItem *> items;
QList<QTreeWidgetItem *> items;
for(it = msgList.begin(); it != msgList.end(); it++)
{
/* check the message flags, to decide which
@ -529,7 +527,7 @@ void MessagesDialog::insertMessages()
}
/* make a widget per friend */
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
/* So Text should be:
* (1) Msg / Broadcast
@ -581,7 +579,7 @@ void MessagesDialog::insertMessages()
QFont qf = item->font(i);
qf.setBold(true);
item->setFont(i, qf);
item -> setIcon(2, (QIcon(":/images/message-mail.png")));
item -> setIcon(2, (QIcon(":/images/message-mail.png")));
//std::cerr << "Setting Item BOLD!" << std::endl;
}
@ -601,12 +599,27 @@ void MessagesDialog::insertMessages()
}
}
void MessagesDialog::updateMessages( QTreeWidgetItem * item, int column )
void MessagesDialog::updateCurrentMessage( QTreeWidgetItem *item , QTreeWidgetItem * )
{
//std::cerr << "MessagesDialog::insertMsgTxtAndFiles()" << std::endl;
insertMsgTxtAndFiles();
setMsgAsRead(item) ;
}
void MessagesDialog::setMsgAsRead(QTreeWidgetItem *item)
{
if(item == NULL)
return ;
for(int i = 0; i < 10; i++)
{
QFont qf = item->font(i);
qf.setBold(false);
item->setFont(i, qf);
}
std::string mid(item->text(5).toStdString());
rsMsgs->MessageRead(mid);
}
void MessagesDialog::insertMsgTxtAndFiles()
{
@ -654,7 +667,7 @@ void MessagesDialog::insertMsgTxtAndFiles()
return;
}
const std::list<FileInfo> &recList = msgInfo.files;
const std::list<FileInfo> &recList = msgInfo.files;
std::list<FileInfo>::const_iterator it;
/* get a link to the table */
@ -662,18 +675,18 @@ void MessagesDialog::insertMsgTxtAndFiles()
/* get the MessageInfo */
tree->clear();
tree->setColumnCount(5);
tree->clear();
tree->setColumnCount(5);
QList<QTreeWidgetItem *> items;
QList<QTreeWidgetItem *> items;
for(it = recList.begin(); it != recList.end(); it++)
{
/* make a widget per person */
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
/* (0) Filename */
item -> setText(0, QString::fromStdString(it->fname));
//std::cerr << "Msg FileItem(" << it->fname.length() << ") :" << it->fname << std::endl;
/* (1) Size */
{
std::ostringstream out;
@ -686,9 +699,9 @@ void MessagesDialog::insertMsgTxtAndFiles()
out << it->rank;
item -> setText(2, QString::fromStdString(out.str()));
}
item -> setText(3, QString::fromStdString(it->hash));
/* add to the list */
items.append(item);
}
@ -747,12 +760,8 @@ void MessagesDialog::insertMsgTxtAndFiles()
}
std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Msg Displayed OK!" << std::endl;
/* finally mark message as read! */
rsMsgs -> MessageRead(mid);
}
bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid)
{
/* Locate the current Message */
@ -774,39 +783,21 @@ bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid)
void MessagesDialog::removemessage()
{
#ifdef TO_REMOVE
//std::cerr << "MessagesDialog::removemessage()" << std::endl;
std::string cid, mid;
if (!getCurrentMsg(cid, mid))
{
//std::cerr << "MessagesDialog::removemessage()";
//std::cerr << " No Message selected" << std::endl;
return;
}
#endif
QList<QTreeWidgetItem*> list(ui.msgWidget->selectedItems()) ;
int maxrow = -1 ;
for(QList<QTreeWidgetItem*>::const_iterator it(list.begin());it!=list.end();++it)
maxrow = std::max(maxrow,ui.msgWidget->indexOfTopLevelItem(*it)) ;
QTreeWidgetItem *next = ui.msgWidget->topLevelItem(maxrow+1) ;
for(QList<QTreeWidgetItem*>::const_iterator it(list.begin());it!=list.end();++it)
rsMsgs->MessageDelete((*it)->text(5).toStdString());
return;
}
void MessagesDialog::markMsgAsRead()
{
//std::cerr << "MessagesDialog::markMsgAsRead()" << std::endl;
std::string cid, mid;
if (!getCurrentMsg(cid, mid))
{
//std::cerr << "MessagesDialog::markMsgAsRead()";
//std::cerr << " No Message selected" << std::endl;
return;
}
rsMsgs -> MessageRead(mid);
if(next != NULL)
ui.msgWidget->setCurrentItem(next) ;
insertMessages();
return;
}

View file

@ -35,21 +35,19 @@ public:
/** Default Constructor */
MessagesDialog(QWidget *parent = 0);
/** Default Destructor */
void insertMessages();
void insertMsgTxtAndFiles();
virtual void keyPressEvent(QKeyEvent *) ;
public slots:
void insertMessages();
private slots:
/** Create the context popup menu and it's submenus */
void messageslistWidgetCostumPopupMenu( QPoint point );
void msgfilelistWidgetCostumPopupMenu(QPoint);
void changeBox( int newrow );
void updateMessages ( QTreeWidgetItem * item, int column );
void changeBox( int newrow );
void updateCurrentMessage ( QTreeWidgetItem * item, QTreeWidgetItem * item2 );
void newmessage();
@ -61,7 +59,6 @@ void updateMessages ( QTreeWidgetItem * item, int column );
void printpreview();
void removemessage();
void markMsgAsRead();
void getcurrentrecommended();
void getallrecommended();
@ -72,6 +69,7 @@ void updateMessages ( QTreeWidgetItem * item, int column );
private:
bool getCurrentMsg(std::string &cid, std::string &mid);
void setMsgAsRead(QTreeWidgetItem *);
std::string mCurrCertId;
std::string mCurrMsgId;

View file

@ -42,7 +42,6 @@ public:
MessengerWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
/** Default Destructor */
void insertPeers();
void setChatDialog(PeersDialog *cd);
NetworkDialog *networkDialog2;
@ -51,6 +50,7 @@ public:
public slots:
void insertPeers();
/** Called when this dialog is to be displayed */
void show();

View file

@ -42,10 +42,10 @@ public:
NetworkDialog(QWidget *parent = 0);
/** Default Destructor */
void insertConnect();
void showpeerdetails(std::string id);
public slots:
void insertConnect();
std::string loadneighbour();
/* void loadneighbour(); */
void setLogInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));

View file

@ -48,13 +48,11 @@ public:
void clearOldChats();
void loadEmoticonsgroupchat();
void insertPeers();
void setChatDialog(ChatDialog *cd);
public slots:
void insertPeers();
void toggleSendItem( QTreeWidgetItem *item, int col );
void insertChat();

View file

@ -70,6 +70,7 @@ TransfersDialog::TransfersDialog(QWidget *parent)
DLDelegate = new DLListDelegate();
ui.downloadList->setItemDelegate(DLDelegate);
ui.downloadList->setAutoScroll(false) ;
//Selection Setup
selection = ui.downloadList->selectionModel();
@ -108,6 +109,7 @@ TransfersDialog::TransfersDialog(QWidget *parent)
ULDelegate = new ULListDelegate();
ui.uploadsList->setItemDelegate(ULDelegate);
ui.uploadsList->setAutoScroll(false) ;
ui.uploadsList->setRootIsDecorated(false);
//Selection Setup

View file

@ -39,35 +39,33 @@ class QStandardItemModel;
class TransfersDialog : public MainPage
{
Q_OBJECT
Q_OBJECT
public:
/** Default Constructor */
TransfersDialog(QWidget *parent = 0);
/** Default Destructor */
~TransfersDialog();
public:
/** Default Constructor */
TransfersDialog(QWidget *parent = 0);
/** Default Destructor */
~TransfersDialog();
public slots:
void insertTransfers();
private slots:
/** Create the context popup menu and it's submenus */
void downloadListCostumPopupMenu( QPoint point );
void insertTransfers();
void cancel();
/** removes finished Downloads**/
void clearcompleted();
void playSelectedTransfer();
private slots:
/** Create the context popup menu and it's submenus */
void downloadListCostumPopupMenu( QPoint point );
void cancel();
/** removes finished Downloads**/
void clearcompleted();
void playSelectedTransfer();
signals:
void playFiles(QStringList files);
signals:
void playFiles(QStringList files);
private:
QStandardItemModel *DLListModel;
QStandardItemModel *ULListModel;
private:
QStandardItemModel *DLListModel;
QStandardItemModel *ULListModel;
QItemSelectionModel *selection;
DLListDelegate *DLDelegate;
ULListDelegate *ULDelegate;
@ -78,26 +76,26 @@ private:
qlonglong completed, remaining;
/** Create the actions on the tray menu or menubar */
void createActions();
/** Create the actions on the tray menu or menubar */
void createActions();
/** Define the popup menus for the Context menu */
QMenu* contextMnu;
/** Defines the actions for the context menu */
QAction* showdowninfoAct;
QAction* cancelAct;
QAction* clearcompletedAct;
/** Define the popup menus for the Context menu */
QMenu* contextMnu;
/** Defines the actions for the context menu */
QAction* showdowninfoAct;
QAction* cancelAct;
QAction* clearcompletedAct;
QTreeView *downloadList;
QTreeView *downloadList;
/** Adds a new action to the toolbar. */
void addAction(QAction *action, const char *slot = 0);
/** Adds a new action to the toolbar. */
void addAction(QAction *action, const char *slot = 0);
/** Qt Designer generated object */
Ui::TransfersDialog ui;
public slots:
int addItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
/** Qt Designer generated object */
Ui::TransfersDialog ui;
public slots:
int addItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
void delItem(int row);
int addUploadItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining);
@ -105,7 +103,7 @@ public slots:
void editItem(int row, int column, QVariant data);
void updateProgress(int value);
double getProgress(int row, QStandardItemModel *model);
double getSpeed(int row, QStandardItemModel *model);
QString getFileName(int row, QStandardItemModel *model);

View file

@ -152,9 +152,15 @@ int main(int argc, char *argv[])
// I'm using a signal to transfer the hashing info to the mainwindow, because Qt schedules signals properly to
// avoid clashes between infos from threads.
//
QObject::connect(notify,SIGNAL(hashingInfo(const QString&)),w,SLOT(updateHashingInfo(const QString&))) ;
QObject::connect(notify,SIGNAL(filesPreMod( bool)),w->sharedfilesDialog,SLOT(preModDirectories(bool))) ;
QObject::connect(notify,SIGNAL(filesPostMod( bool)),w->sharedfilesDialog,SLOT(postModDirectories(bool))) ;
QObject::connect(notify,SIGNAL(hashingInfoChanged(const QString&)),w ,SLOT(updateHashingInfo(const QString&))) ;
QObject::connect(notify,SIGNAL(filesPreModChanged(bool)) ,w->sharedfilesDialog,SLOT(preModDirectories(bool) )) ;
QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w->sharedfilesDialog,SLOT(postModDirectories(bool) )) ;
QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ;
QObject::connect(notify,SIGNAL(friendsChanged()) ,w->messengerWindow ,SLOT(insertPeers() )) ;
QObject::connect(notify,SIGNAL(friendsChanged()) ,w->peersDialog ,SLOT(insertPeers() )) ;
QObject::connect(notify,SIGNAL(neighborsChanged()) ,w->networkDialog ,SLOT(insertConnect() )) ;
QObject::connect(notify,SIGNAL(messagesChanged()) ,w->messagesDialog ,SLOT(insertMessages() )) ;
QObject::connect(notify,SIGNAL(configChanged()) ,w->messagesDialog ,SLOT(displayConfig() )) ;
/* only show window, if not startMinimized */
if (!startMinimised)

View file

@ -38,7 +38,7 @@ void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
void NotifyQt::notifyHashingInfo(std::string fileinfo)
{
emit hashingInfo(QString::fromStdString(fileinfo)) ;
emit hashingInfoChanged(QString::fromStdString(fileinfo)) ;
}
void NotifyQt::notifyChat()
@ -56,27 +56,30 @@ void NotifyQt::notifyListChange(int list, int type)
switch(list)
{
case NOTIFY_LIST_NEIGHBOURS:
//displayNeighbours();
emit neighborsChanged();
break;
case NOTIFY_LIST_FRIENDS:
//displayFriends();
emit friendsChanged() ;
break;
case NOTIFY_LIST_DIRLIST:
emit filesPostMod(false) ; /* Remote */
emit filesPostMod(true) ; /* Local */
emit filesPostModChanged(false) ; /* Remote */
emit filesPostModChanged(true) ; /* Local */
break;
case NOTIFY_LIST_SEARCHLIST:
//displaySearch();
break;
case NOTIFY_LIST_MESSAGELIST:
//displayMessages();
emit messagesChanged() ;
break;
case NOTIFY_LIST_CHANNELLIST:
//displayChannels();
break;
case NOTIFY_LIST_TRANSFERLIST:
//displayTransfers();
emit transfersChanged() ;
break;
case NOTIFY_LIST_CONFIG:
emit configChanged() ;
break ;
default:
break;
}
@ -95,11 +98,11 @@ void NotifyQt::notifyListPreChange(int list, int type)
//preDisplayNeighbours();
break;
case NOTIFY_LIST_FRIENDS:
//preDisplayFriends();
emit friendsChanged() ;
break;
case NOTIFY_LIST_DIRLIST:
emit filesPreMod(false) ; /* remote */
emit filesPreMod(true) ; /* local */
emit filesPreModChanged(false) ; /* remote */
emit filesPreModChanged(true) ; /* local */
break;
case NOTIFY_LIST_SEARCHLIST:
//preDisplaySearch();
@ -127,63 +130,31 @@ void NotifyQt::notifyListPreChange(int list, int type)
void NotifyQt::UpdateGUI()
{
iface->lockData(); /* Lock Interface */
/* make local -> so we can release iface */
bool uNeigh = iface->hasChanged(RsIface::Neighbour);
bool uFri = iface->hasChanged(RsIface::Friend);
bool uTrans = iface->hasChanged(RsIface::Transfer);
//bool uChat = iface->hasChanged(RsIface::Chat);
bool uMsg = iface->hasChanged(RsIface::Message);
bool uChan = iface->hasChanged(RsIface::Channel);
bool uRecom = iface->hasChanged(RsIface::Recommend);
bool uConf = iface->hasChanged(RsIface::Config);
iface->unlockData(); /* UnLock Interface */
/* hack to force updates until we've fixed that part */
static time_t lastTs = 0;
static time_t lastTs = 0;
if (time(NULL) > lastTs + 5)
if (time(NULL) > lastTs) // always update, every 1 sec.
{
lastTs = time(NULL);
uNeigh = true;
uFri = true;
uTrans = true;
//uChat = true;
uMsg = true;
uChan = true;
uRecom = true;
uConf = true;
emit transfersChanged();
emit friendsChanged() ;
}
if (uNeigh)
displayNeighbours();
if (uFri)
displayFriends();
if (uTrans)
displayTransfers();
//if (uChat)
// displayChat();
if (uMsg)
displayMessages();
if (uChan)
if (time(NULL) > lastTs + 5) // update every 5 seconds. I don't know what to do with these.
{
displayChannels();
}
static bool already_updated = false ; // these only update once at start because they may already have been set before
// the gui is running, then they get updated by callbacks.
if(!already_updated)
{
emit messagesChanged() ;
emit neighborsChanged();
emit configChanged();
already_updated = true ;
}
/* TODO
if (uRecom)
displayRecommends();
if (uConf)
displayConfig();
*/
/* Finally Check for PopupMessages / System Error Messages */
if (rsNotify)
@ -265,22 +236,6 @@ static time_t lastTs = 0;
}
}
void NotifyQt::displayNeighbours()
{
/* Do the GUI */
if (cDialog)
cDialog->insertConnect();
}
void NotifyQt::displayFriends()
{
if (pDialog)
pDialog->insertPeers();
if (mWindow)
mWindow->insertPeers();
}
void NotifyQt::displaySearch()
{
iface->lockData(); /* Lock Interface */
@ -293,13 +248,6 @@ void NotifyQt::displaySearch()
iface->unlockData(); /* UnLock Interface */
}
void NotifyQt::displayMessages()
{
if (mDialog)
mDialog -> insertMessages();
}
void NotifyQt::displayChat()
{
iface->lockData(); /* Lock Interface */

View file

@ -51,9 +51,14 @@ class NotifyQt: public QObject, public NotifyBase
// It's beneficial to send info to the GUI using signals, because signals are thread-safe
// as they get queued by Qt.
//
void hashingInfo(const QString&) const ;
void filesPreMod(bool) const ;
void filesPostMod(bool) const ;
void hashingInfoChanged(const QString&) const ;
void filesPreModChanged(bool) const ;
void filesPostModChanged(bool) const ;
void transfersChanged() const ;
void friendsChanged() const ;
void neighborsChanged() const ;
void messagesChanged() const ;
void configChanged() const ;
public slots:

View file

@ -202,13 +202,14 @@ class NotifyBase
virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; }
};
const int NOTIFY_LIST_NEIGHBOURS = 1;
const int NOTIFY_LIST_FRIENDS = 2;
const int NOTIFY_LIST_DIRLIST = 3;
const int NOTIFY_LIST_SEARCHLIST = 4;
const int NOTIFY_LIST_MESSAGELIST = 5;
const int NOTIFY_LIST_CHANNELLIST = 6;
const int NOTIFY_LIST_NEIGHBOURS = 1;
const int NOTIFY_LIST_FRIENDS = 2;
const int NOTIFY_LIST_DIRLIST = 3;
const int NOTIFY_LIST_SEARCHLIST = 4;
const int NOTIFY_LIST_MESSAGELIST = 5;
const int NOTIFY_LIST_CHANNELLIST = 6;
const int NOTIFY_LIST_TRANSFERLIST = 7;
const int NOTIFY_LIST_CONFIG = 8;
const int NOTIFY_TYPE_SAME = 0x01;
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */