1#include "FrmListConnects.h"
2#include "RabbitCommonDir.h"
5#include <QStandardItem>
10CFrmListConnects::CFrmListConnects(
CClient* pClient,
bool bDock, QWidget *parent) :
13 m_ptbConnect(nullptr),
19 m_pDockTitleBar(nullptr)
21 setFocusPolicy(Qt::NoFocus);
22 setAttribute(Qt::WA_DeleteOnClose);
23 setLayout(
new QGridLayout(
this));
24 setWindowTitle(tr(
"List connections"));
26 m_pToolBar =
new QToolBar(
this);
27 m_pConnect = m_pToolBar->addAction(
28 QIcon::fromTheme(
"network-wired"), tr(
"Connect"),
29 this, SLOT(slotConnect()));
30 m_pConnect->setStatusTip(tr(
"Connect"));
31 m_pConnect->setToolTip(tr(
"Connect"));
32 m_pEditConnect = m_pToolBar->addAction(
33 QIcon::fromTheme(
"edit-connect"), tr(
"Edit and Connect"),
34 this, SLOT(slotEditConnect()));
35 m_pEditConnect->setStatusTip(tr(
"Edit and Connect"));
36 m_pEditConnect->setToolTip(tr(
"Edit and Connect"));
37 m_pToolBar->addSeparator();
39 m_ptbConnect =
new QToolButton(m_pToolBar);
40 m_ptbConnect->setFocusPolicy(Qt::NoFocus);
41 m_ptbConnect->setPopupMode(QToolButton::InstantPopup);
43 m_pMenuNew =
new QMenu(tr(
"New"),
this);
44 m_pMenuNew->setIcon(QIcon::fromTheme(
"add"));
45 m_ptbConnect->setMenu(m_pMenuNew);
46 m_ptbConnect->setIcon(m_pMenuNew->icon());
47 m_ptbConnect->setText(tr(
"New"));
48 m_ptbConnect->setToolTip(tr(
"New"));
49 m_ptbConnect->setStatusTip(tr(
"New"));
50 m_pToolBar->addWidget(m_ptbConnect);
51 m_pClient->EnumPlugins(
this);
52 m_pEdit = m_pToolBar->addAction(QIcon::fromTheme(
"edit"), tr(
"Edit"),
53 this, SLOT(slotEdit()));
54 m_pEdit->setStatusTip(tr(
"Edit"));
55 m_pEdit->setToolTip(tr(
"Edit"));
56 m_pCopy = m_pToolBar->addAction(QIcon::fromTheme(
"edit-copy"), tr(
"Copy"),
57 this, SLOT(slotCopy()));
58 m_pCopy->setStatusTip(tr(
"Copy"));
59 m_pCopy->setToolTip(tr(
"Copy"));
60 m_pDelete = m_pToolBar->addAction(
61 QIcon::fromTheme(
"edit-delete"), tr(
"Delete"),
62 this, SLOT(slotDelete()));
63 m_pDelete->setToolTip(tr(
"Delete"));
64 m_pDelete->setStatusTip(tr(
"Delete"));
65 m_pDetail = m_pToolBar->addAction(
66 QIcon::fromTheme(
"dialog-information"), tr(
"Detail"),
67 this, SLOT(slotDetail()));
68 m_pDetail->setCheckable(
true);
69 m_pDetail->setChecked(
false);
70 m_pDetail->setToolTip(tr(
"Detail"));
71 m_pDetail->setStatusTip(tr(
"Detail"));
72 m_pToolBar->addSeparator();
74 m_pRefresh = m_pToolBar->addAction(
75 QIcon::fromTheme(
"view-refresh"),
77 this, SLOT(slotLoadFiles()));
78 m_pRefresh->setToolTip(tr(
"Refresh"));
79 m_pRefresh->setStatusTip(tr(
"Refresh"));
81 QAction* pClose = m_pToolBar->addAction(
82 QIcon::fromTheme(
"window-close"), tr(
"Close"),
84 pClose->setStatusTip(tr(
"Close"));
85 pClose->setToolTip(tr(
"Close"));
88 layout()->addWidget(m_pToolBar);
91 m_pDockTitleBar =
new RabbitCommon::CTitleBar(parent);
93 QMenu* pMenu =
new QMenu(tr(
"Tools"), m_pDockTitleBar);
94 QPushButton* pTools = m_pDockTitleBar->CreateSmallPushButton(
95 QIcon::fromTheme(
"tools"), m_pDockTitleBar);
96 pTools->setToolTip(tr(
"Tools"));
97 pTools->setMenu(pMenu);
98 QList<QWidget*> lstWidget;
100 m_pDockTitleBar->AddWidgets(lstWidget);
102 pMenu->addAction(m_pConnect);
103 pMenu->addAction(m_pEditConnect);
104 pMenu->addMenu(m_pMenuNew);
105 pMenu->addAction(m_pEdit);
106 pMenu->addAction(m_pCopy);
107 pMenu->addAction(m_pDelete);
108 pMenu->addAction(m_pDetail);
109 pMenu->addAction(m_pRefresh);
113 m_pTableView =
new QTableView(
this);
114 m_pTableView->setContextMenuPolicy(Qt::CustomContextMenu);
115 bool check = connect(m_pTableView,
116 SIGNAL(customContextMenuRequested(
const QPoint &)),
117 this, SLOT(slotCustomContextMenu(
const QPoint &)));
119 check = connect(m_pTableView, SIGNAL(doubleClicked(
const QModelIndex &)),
120 this, SLOT(slotDoubleClicked(
const QModelIndex&)));
122 layout()->addWidget(m_pTableView);;
124 m_pModel =
new QStandardItemModel(m_pTableView);
125 m_pTableView->setModel(m_pModel);
126 m_pTableView->verticalHeader()->hide();
127 m_pTableView->setSelectionMode(QAbstractItemView::SingleSelection);
128 m_pTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
129 m_pTableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
130 m_pModel->setHorizontalHeaderItem(0,
new QStandardItem(tr(
"Name")));
131 m_pModel->setHorizontalHeaderItem(1,
new QStandardItem(tr(
"Protocol")));
132 m_pModel->setHorizontalHeaderItem(2,
new QStandardItem(tr(
"Date")));
133 m_pModel->setHorizontalHeaderItem(3,
new QStandardItem(tr(
"ID")));
135 m_pModel->setHorizontalHeaderItem(m_nFileRow,
new QStandardItem(tr(
"File")));
136 if(!m_pDetail->isChecked()) {
137 m_pTableView->hideColumn(3);
138 m_pTableView->hideColumn(m_nFileRow);
150 m_pTableView->horizontalHeader()->setSectionResizeMode(
151#
if defined(DEBUG) && !defined(Q_OS_ANDROID)
154 QHeaderView::ResizeToContents);
161 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
162 QModelIndexList lstIndex;
164 lstIndex = pSelect->selectedRows();
165 if(m_pModel->rowCount() > 0 && lstIndex.isEmpty())
167 m_pTableView->selectRow(0);
172CFrmListConnects::~CFrmListConnects()
176void CFrmListConnects::slotLoadFiles()
178 m_pModel->removeRows(0, m_pModel->rowCount());
179 QString szPath = RabbitCommon::CDir::Instance()->GetDirUserData();
181 QStringList files = dir.entryList(QStringList() <<
"*.rrc",
182 QDir::Files, QDir::Time);
183 foreach (
auto fileName, files) {
184 QString szFile = dir.absoluteFilePath(fileName);
185 if(szFile.isEmpty())
continue;
189 QList<QStandardItem*> lstItem;
190 QStandardItem* pName =
new QStandardItem(c->
Icon(), c->
Name());
193 QStandardItem* pProtocol =
new QStandardItem(c->
Protocol());
194 lstItem << pProtocol;
195 QFileInfo fi(szFile);
196 lstItem <<
new QStandardItem(fi.lastModified().toLocalTime().toString());
197 QStandardItem* pId =
new QStandardItem(c->
Id());
199 QStandardItem* pFile =
new QStandardItem(szFile);
201 m_pModel->appendRow(lstItem);
206 if(m_pModel->rowCount() > 0)
208 m_pConnect->setEnabled(
true);
209 m_pEditConnect->setEnabled(
true);
210 m_pEdit->setEnabled(
true);
211 m_pCopy->setEnabled(
true);
212 m_pDelete->setEnabled(
true);
214 m_pConnect->setEnabled(
false);
215 m_pEditConnect->setEnabled(
false);
216 m_pEdit->setEnabled(
false);
217 m_pCopy->setEnabled(
false);
218 m_pDelete->setEnabled(
false);
224int CFrmListConnects::InsertItem(
CConnecter *c, QString& szFile)
226 QList<QStandardItem*> lstItem;
227 QStandardItem* pName =
new QStandardItem(c->
Icon(), c->
Name());
230 QStandardItem* pProtocol =
new QStandardItem(c->
Protocol());
231 lstItem << pProtocol;
232 QFileInfo fi(szFile);
233 lstItem <<
new QStandardItem(fi.lastModified().toString());
234 QStandardItem* pId =
new QStandardItem(c->
Id());
236 QStandardItem* pFile =
new QStandardItem(szFile);
238 m_pModel->insertRow(0, lstItem);
239 m_pTableView->selectRow(0);
246 QAction* pAction = m_pMenuNew->addAction(pPlug->
Protocol()
248 this, SLOT(slotNew()));
251 pAction->setData(
id);
252 pAction->setIcon(pPlug->Icon());
256void CFrmListConnects::slotNew()
258 QAction* pAction =
dynamic_cast<QAction*
>(this->sender());
260 if(
nullptr == c)
return;
265 case QDialog::Rejected:
267 case QDialog::Accepted:
269 QString szFile = RabbitCommon::CDir::Instance()->GetDirUserData()
274 if(d.exists(szFile)) {
275 QMessageBox::StandardButton r
276 = QMessageBox::warning(
278 tr(
"File of connecter is exists. whether to overwrite it? File: %1").arg(szFile),
279 QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No,
280 QMessageBox::StandardButton::No);
281 if(QMessageBox::StandardButton::Ok == r)
291 InsertItem(c, szFile);
300void CFrmListConnects::slotEdit()
302 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
303 QModelIndexList lstIndex = pSelect->selectedRows();
304 foreach(
auto index, lstIndex)
306 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
311 case QDialog::Rejected:
313 case QDialog::Accepted:
321void CFrmListConnects::slotEditConnect()
323 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
324 QModelIndexList lstIndex = pSelect->selectedRows();
325 foreach(
auto index, lstIndex)
327 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
332 case QDialog::Rejected:
334 case QDialog::Accepted:
336 emit sigConnect(szFile);
345void CFrmListConnects::slotCopy()
347 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
348 QModelIndexList lstIndex = pSelect->selectedRows();
349 foreach(
auto index, lstIndex)
351 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
360 case QDialog::Rejected:
362 case QDialog::Accepted:
364 szFile = RabbitCommon::CDir::Instance()->GetDirUserData()
369 if(d.exists(szFile)) {
370 QMessageBox::StandardButton r
371 = QMessageBox::warning(
374 tr(
"File of connecter is exists. whether to overwrite it? "
375 "If select No, please modify the name of connecter"),
376 QMessageBox::StandardButton::Ok
377 | QMessageBox::StandardButton::No
378 | QMessageBox::StandardButton::Cancel,
379 QMessageBox::StandardButton::No);
380 if(QMessageBox::StandardButton::No == r)
385 if(QMessageBox::StandardButton::Cancel == r)
391 InsertItem(c, szFile);
404void CFrmListConnects::slotDelete()
406 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
407 QModelIndexList lstIndex = pSelect->selectedRows();
408 foreach(
auto index, lstIndex)
410 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
413 m_pModel->removeRow(index.row());
417void CFrmListConnects::slotConnect()
419 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
420 QModelIndexList lstIndex = pSelect->selectedRows();
421 foreach(
auto index, lstIndex)
423 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
424 emit sigConnect(szFile);
426 if(!m_bDock) close();
429void CFrmListConnects::slotDetail()
431 if(m_pDetail->isChecked()) {
432 m_pTableView->showColumn(3);
433 m_pTableView->showColumn(m_nFileRow);
435 m_pTableView->hideColumn(3);
436 m_pTableView->hideColumn(m_nFileRow);
440void CFrmListConnects::slotCustomContextMenu(
const QPoint &pos)
444 menu.addAction(QIcon::fromTheme(
"network-wired"),
445 tr(
"Connect"),
this, SLOT(slotConnect()));
446 menu.addAction(tr(
"Edit and Connect"),
this, SLOT(slotEditConnect()));
448 menu.addMenu(m_pMenuNew);
449 menu.addAction(tr(
"Edit"),
this, SLOT(slotEdit()));
450 menu.addAction(QIcon::fromTheme(
"edit-copy"), tr(
"Copy"),
451 this, SLOT(slotCopy()));
452 menu.addAction(QIcon::fromTheme(
"edit-delete"), tr(
"Delete"),
453 this, SLOT(slotDelete()));
455 menu.addAction(QIcon::fromTheme(
"view-refresh"), tr(
"Refresh"),
456 this, SLOT(slotLoadFiles()));
458 menu.exec(mapToGlobal(pos));
461void CFrmListConnects::slotDoubleClicked(
const QModelIndex& index)
463 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
464 emit sigConnect(szFile);
465 if(!m_bDock) close();
virtual CConnecter * LoadConnecter(const QString &szFile)
从文件中新建 CConnecter 指针,所有者是调用者。 当不再使用时,调用者必须负责调用 DeleteConnecter() 删除此指针。 调用者必须连接信号 CConnecter::sigDisc...
virtual CConnecter * CreateConnecter(const QString &id)
新建 CConnecter 指针,所有者是调用者。 当不在使用时,调用者必调用 DeteleConnecter() 须释放指针。 调用者必须连接信号 CConnecter::sigDisconnecte...
virtual int SaveConnecter(QString szFile, CConnecter *pConnecter)
保存连接参数到文件
virtual const QIcon Icon() const
Icon
virtual int OpenDialogSettings(QWidget *parent=nullptr)
打开设置对话框
virtual const QString Description()
Description
virtual const QString Protocol() const
Protocol
virtual const QString Id()
Identity
virtual const QString Name()
Name
virtual int onProcess(const QString &id, CPluginClient *pPlug) override
Process plugins
客户端插件接口。用于建立 CConnecter 实例,它由协议插件实现。
virtual const QString DisplayName() const
在界面上显示的名称
virtual const QString Description() const =0
描述
virtual const QString Protocol() const =0
协议