2018-11-11 10:57:05 -05:00
/*******************************************************************************
* gui / common / FriendSelectionWidget . h *
* *
* Copyright ( C ) 2012 , Retroshare Team < retroshare . project @ gmail . com > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 of the *
* License , or ( at your option ) any later version . *
* *
* This program is distributed in the hope that it will be useful , *
* but WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the *
* GNU Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-01-26 19:32:17 -05:00
# ifndef FRIENDSELECTIONWIDGET_H
# define FRIENDSELECTIONWIDGET_H
# include <QWidget>
2013-02-22 16:42:27 -05:00
# include <QDialog>
2012-01-26 19:32:17 -05:00
2014-03-29 10:18:05 -04:00
# include <gui/gxs/RsGxsUpdateBroadcastPage.h>
# include "util/TokenQueue.h"
2012-01-26 19:32:17 -05:00
namespace Ui {
class FriendSelectionWidget ;
}
class QTreeWidgetItem ;
class RSTreeWidgetItemCompareRole ;
2014-03-29 10:18:05 -04:00
class FriendSelectionWidget : public RsGxsUpdateBroadcastPage , public TokenResponse
2012-01-26 19:32:17 -05:00
{
Q_OBJECT
2012-11-19 11:01:21 -05:00
Q_PROPERTY ( QColor textColorOnline READ textColorOnline WRITE setTextColorOnline )
2012-01-26 19:32:17 -05:00
public :
enum IdType
{
IDTYPE_NONE ,
IDTYPE_GROUP ,
2012-11-24 09:48:31 -05:00
IDTYPE_SSL ,
2014-03-29 10:18:05 -04:00
IDTYPE_GPG ,
IDTYPE_GXS
2012-01-26 19:32:17 -05:00
} ;
enum Modus
{
MODUS_SINGLE ,
MODUS_MULTI ,
MODUS_CHECK
} ;
2012-11-24 09:48:31 -05:00
enum ShowType {
2013-09-07 10:02:24 -04:00
SHOW_NONE = 0 ,
2013-05-29 17:32:02 -04:00
SHOW_GROUP = 1 ,
SHOW_GPG = 2 ,
SHOW_SSL = 4 ,
SHOW_NON_FRIEND_GPG = 8 ,
2015-12-04 22:42:56 -05:00
SHOW_GXS = 16 ,
SHOW_CONTACTS = 32
2012-11-24 09:48:31 -05:00
} ;
Q_DECLARE_FLAGS ( ShowTypes , ShowType )
2012-01-26 19:32:17 -05:00
public :
explicit FriendSelectionWidget ( QWidget * parent = 0 ) ;
~ FriendSelectionWidget ( ) ;
void setHeaderText ( const QString & text ) ;
void setModus ( Modus modus ) ;
2012-11-24 09:48:31 -05:00
void setShowType ( ShowTypes types ) ;
2013-01-22 19:22:17 -05:00
int addColumn ( const QString & title ) ;
2012-01-26 19:32:17 -05:00
void start ( ) ;
2015-08-21 18:57:26 -04:00
bool isSortByState ( ) ;
2018-02-07 13:00:08 -05:00
bool isFilterConnected ( ) ;
2015-08-21 12:41:09 -04:00
2012-01-26 19:32:17 -05:00
int selectedItemCount ( ) ;
2014-03-17 16:56:06 -04:00
std : : string selectedId ( IdType & idType ) ;
2015-04-17 17:36:22 -04:00
template < class ID_CLASS , FriendSelectionWidget : : IdType TYPE > void selectedIds ( std : : set < ID_CLASS > & ids , bool onlyDirectSelected )
2014-03-17 16:56:06 -04:00
{
2015-04-17 17:36:22 -04:00
std : : set < std : : string > tmpids ;
2014-03-17 16:56:06 -04:00
selectedIds ( TYPE , tmpids , onlyDirectSelected ) ;
ids . clear ( ) ;
2015-04-17 17:36:22 -04:00
for ( std : : set < std : : string > : : const_iterator it ( tmpids . begin ( ) ) ; it ! = tmpids . end ( ) ; + + it )
ids . insert ( ID_CLASS ( * it ) ) ;
2014-03-17 16:56:06 -04:00
}
2015-04-17 17:36:22 -04:00
template < class ID_CLASS , FriendSelectionWidget : : IdType TYPE > void setSelectedIds ( const std : : set < ID_CLASS > & ids , bool add )
2014-03-17 16:56:06 -04:00
{
2015-04-17 17:36:22 -04:00
std : : set < std : : string > tmpids ;
for ( typename std : : set < ID_CLASS > : : const_iterator it ( ids . begin ( ) ) ; it ! = ids . end ( ) ; + + it )
tmpids . insert ( ( * it ) . toStdString ( ) ) ;
2014-03-17 16:56:06 -04:00
setSelectedIds ( TYPE , tmpids , add ) ;
}
2012-01-26 19:32:17 -05:00
2013-01-22 19:22:17 -05:00
void itemsFromId ( IdType idType , const std : : string & id , QList < QTreeWidgetItem * > & items ) ;
void items ( QList < QTreeWidgetItem * > & items , IdType = IDTYPE_NONE ) ;
IdType idTypeFromItem ( QTreeWidgetItem * item ) ;
std : : string idFromItem ( QTreeWidgetItem * item ) ;
2012-11-19 11:01:21 -05:00
QColor textColorOnline ( ) const { return mTextColorOnline ; }
void setTextColorOnline ( QColor color ) { mTextColorOnline = color ; }
2015-08-21 12:41:09 -04:00
// Add QAction to context menu (action won't be deleted)
void addContextMenuAction ( QAction * action ) ;
2012-11-19 11:01:21 -05:00
protected :
void changeEvent ( QEvent * e ) ;
2014-03-29 10:18:05 -04:00
virtual void loadRequest ( const TokenQueue * queue , const TokenRequest & req ) ;
virtual void updateDisplay ( bool complete ) ;
2012-01-26 19:32:17 -05:00
signals :
2013-01-22 19:22:17 -05:00
void itemAdded ( int idType , const QString & id , QTreeWidgetItem * item ) ;
2012-01-26 19:32:17 -05:00
void contentChanged ( ) ;
2013-01-22 19:22:17 -05:00
void doubleClicked ( int idType , const QString & id ) ;
void itemChanged ( int idType , const QString & id , QTreeWidgetItem * item , int column ) ;
2015-08-21 12:41:09 -04:00
void itemSelectionChanged ( ) ;
public slots :
2015-08-21 18:57:26 -04:00
void sortByState ( bool sort ) ;
2018-02-07 13:00:08 -05:00
void filterConnected ( bool filter ) ;
2012-01-26 19:32:17 -05:00
private slots :
2013-06-20 08:27:51 -04:00
void groupsChanged ( int type ) ;
2012-01-26 19:32:17 -05:00
void peerStatusChanged ( const QString & peerId , int status ) ;
2012-04-05 17:03:03 -04:00
void filterItems ( const QString & text ) ;
2012-01-26 19:32:17 -05:00
void contextMenuRequested ( const QPoint & pos ) ;
void itemDoubleClicked ( QTreeWidgetItem * item , int column ) ;
void itemChanged ( QTreeWidgetItem * item , int column ) ;
2013-05-29 17:32:02 -04:00
void selectAll ( ) ;
void deselectAll ( ) ;
2012-01-26 19:32:17 -05:00
private :
2013-06-20 08:27:51 -04:00
void fillList ( ) ;
2013-06-19 09:18:15 -04:00
void secured_fillList ( ) ;
2012-01-26 19:32:17 -05:00
2015-04-17 17:36:22 -04:00
void selectedIds ( IdType idType , std : : set < std : : string > & ids , bool onlyDirectSelected ) ;
void setSelectedIds ( IdType idType , const std : : set < std : : string > & ids , bool add ) ;
2012-01-26 19:32:17 -05:00
2014-03-29 10:18:05 -04:00
void requestGXSIdList ( ) ;
2015-08-21 12:41:09 -04:00
private :
2013-01-22 19:22:17 -05:00
bool mStarted ;
RSTreeWidgetItemCompareRole * mCompareRole ;
Modus mListModus ;
ShowTypes mShowTypes ;
bool mInGroupItemChanged ;
bool mInGpgItemChanged ;
bool mInSslItemChanged ;
bool mInFillList ;
2015-08-21 12:41:09 -04:00
QAction * mActionSortByState ;
2018-02-07 13:00:08 -05:00
QAction * mActionFilterConnected ;
2012-01-26 19:32:17 -05:00
2012-11-19 11:01:21 -05:00
/* Color definitions (for standard see qss.default) */
QColor mTextColorOnline ;
2012-01-26 19:32:17 -05:00
Ui : : FriendSelectionWidget * ui ;
2013-05-29 17:32:02 -04:00
friend class FriendSelectionDialog ;
2014-03-29 10:18:05 -04:00
std : : vector < RsGxsGroupId > gxsIds ;
TokenQueue * mIdQueue ;
2015-08-21 12:41:09 -04:00
QList < QAction * > mContextMenuActions ;
2018-08-30 04:54:52 -04:00
std : : set < RsGxsId > mPreSelectedGxsIds ; // because loading of GxsIds is asynchroneous we keep selected Ids from the client in a list here and use it to initialize after loading them.
2012-01-26 19:32:17 -05:00
} ;
2012-11-24 09:48:31 -05:00
Q_DECLARE_OPERATORS_FOR_FLAGS ( FriendSelectionWidget : : ShowTypes )
2012-01-26 19:32:17 -05:00
# endif // FRIENDSELECTIONWIDGET_H