1#include "FrmListRecentConnects.h"
2#include "RabbitCommonDir.h"
5#include <QStandardItem>
10CFrmListRecentConnects::CFrmListRecentConnects(
14 m_ParameterApp(parameterApp),
16 m_ptbConnect(nullptr),
22 m_pDockTitleBar(nullptr)
24 setFocusPolicy(Qt::NoFocus);
25 setAttribute(Qt::WA_DeleteOnClose);
26 setLayout(
new QVBoxLayout(
this));
27 setWindowTitle(tr(
"List recent connections"));
29 m_pToolBar =
new QToolBar(
this);
30 m_pToolBar->setVisible(m_ParameterApp.GetDockListRecentShowToolBar());
31 m_pConnect = m_pToolBar->addAction(
32 QIcon::fromTheme(
"network-wired"), tr(
"Connect"),
33 this, SLOT(slotConnect()));
34 m_pConnect->setStatusTip(tr(
"Connect"));
35 m_pConnect->setToolTip(tr(
"Connect"));
36 m_pEditConnect = m_pToolBar->addAction(
37 QIcon::fromTheme(
"edit-connect"), tr(
"Edit and Connect"),
38 this, SLOT(slotEditConnect()));
39 m_pEditConnect->setStatusTip(tr(
"Edit and Connect"));
40 m_pEditConnect->setToolTip(tr(
"Edit and Connect"));
41 m_pToolBar->addSeparator();
43 m_ptbConnect =
new QToolButton(m_pToolBar);
44 m_ptbConnect->setFocusPolicy(Qt::NoFocus);
45 m_ptbConnect->setPopupMode(QToolButton::InstantPopup);
47 m_pMenuNew =
new QMenu(tr(
"New"),
this);
48 m_pMenuNew->setIcon(QIcon::fromTheme(
"add"));
49 m_ptbConnect->setMenu(m_pMenuNew);
50 m_ptbConnect->setIcon(m_pMenuNew->icon());
51 m_ptbConnect->setText(tr(
"New"));
52 m_ptbConnect->setToolTip(tr(
"New"));
53 m_ptbConnect->setStatusTip(tr(
"New"));
54 m_pToolBar->addWidget(m_ptbConnect);
55 m_pClient->EnumPlugins(
this);
56 m_pEdit = m_pToolBar->addAction(QIcon::fromTheme(
"edit"), tr(
"Edit"),
57 this, SLOT(slotEdit()));
58 m_pEdit->setStatusTip(tr(
"Edit"));
59 m_pEdit->setToolTip(tr(
"Edit"));
60 m_pCopy = m_pToolBar->addAction(QIcon::fromTheme(
"edit-copy"), tr(
"Copy"),
61 this, SLOT(slotCopy()));
62 m_pCopy->setStatusTip(tr(
"Copy"));
63 m_pCopy->setToolTip(tr(
"Copy"));
64 m_pDelete = m_pToolBar->addAction(
65 QIcon::fromTheme(
"edit-delete"), tr(
"Delete"),
66 this, SLOT(slotDelete()));
67 m_pDelete->setToolTip(tr(
"Delete"));
68 m_pDelete->setStatusTip(tr(
"Delete"));
69 m_pDetail = m_pToolBar->addAction(
70 QIcon::fromTheme(
"dialog-information"), tr(
"Detail"),
71 this, SLOT(slotDetail()));
72 m_pDetail->setCheckable(
true);
73 m_pDetail->setChecked(
false);
74 m_pDetail->setToolTip(tr(
"Detail"));
75 m_pDetail->setStatusTip(tr(
"Detail"));
76 m_pToolBar->addSeparator();
78 m_pRefresh = m_pToolBar->addAction(
79 QIcon::fromTheme(
"view-refresh"),
81 this, SLOT(slotLoadFiles()));
82 m_pRefresh->setToolTip(tr(
"Refresh"));
83 m_pRefresh->setStatusTip(tr(
"Refresh"));
85 QAction* pClose = m_pToolBar->addAction(
86 QIcon::fromTheme(
"window-close"), tr(
"Close"),
88 pClose->setStatusTip(tr(
"Close"));
89 pClose->setToolTip(tr(
"Close"));
92 layout()->addWidget(m_pToolBar);
95 m_pDockTitleBar =
new RabbitCommon::CTitleBar(parent);
97 QMenu* pMenu =
new QMenu(tr(
"Tools"), m_pDockTitleBar);
98 QPushButton* pTools = m_pDockTitleBar->CreateSmallPushButton(
99 QIcon::fromTheme(
"tools"), m_pDockTitleBar);
100 pTools->setToolTip(tr(
"Tools"));
101 pTools->setMenu(pMenu);
102 QList<QWidget*> lstWidget;
104 m_pDockTitleBar->AddWidgets(lstWidget);
106 pMenu->addAction(m_pConnect);
107 pMenu->addAction(m_pEditConnect);
108 pMenu->addMenu(m_pMenuNew);
109 pMenu->addAction(m_pEdit);
110 pMenu->addAction(m_pCopy);
111 pMenu->addAction(m_pDelete);
112 pMenu->addAction(m_pDetail);
113 pMenu->addAction(m_pRefresh);
114 pMenu->addSeparator();
115 auto pShowToolBar = pMenu->addAction(tr(
"Show tool bar"),
this, [&](){
116 QAction* a = (QAction*)sender();
118 m_pToolBar->setVisible(a->isChecked());
119 m_ParameterApp.SetDockListRecentShowToolBar(a->isChecked());
120 m_ParameterApp.Save();
123 pShowToolBar->setCheckable(
true);
124 pShowToolBar->setChecked(m_ParameterApp.GetDockListRecentShowToolBar());
128 m_pTableView =
new QTableView(
this);
129 m_pTableView->setContextMenuPolicy(Qt::CustomContextMenu);
130 bool check = connect(m_pTableView,
131 SIGNAL(customContextMenuRequested(
const QPoint &)),
132 this, SLOT(slotCustomContextMenu(
const QPoint &)));
134 check = connect(m_pTableView, SIGNAL(doubleClicked(
const QModelIndex &)),
135 this, SLOT(slotDoubleClicked(
const QModelIndex&)));
137 layout()->addWidget(m_pTableView);
139 m_pModel =
new QStandardItemModel(m_pTableView);
140 m_pTableView->setModel(m_pModel);
141 m_pTableView->verticalHeader()->hide();
142 m_pTableView->setSelectionMode(QAbstractItemView::SingleSelection);
143 m_pTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
144 m_pTableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
145 m_pModel->setHorizontalHeaderItem(0,
new QStandardItem(tr(
"Name")));
146 m_pModel->setHorizontalHeaderItem(1,
new QStandardItem(tr(
"Protocol")));
147 m_pModel->setHorizontalHeaderItem(2,
new QStandardItem(tr(
"Date")));
148 m_pModel->setHorizontalHeaderItem(3,
new QStandardItem(tr(
"ID")));
150 m_pModel->setHorizontalHeaderItem(m_nFileRow,
new QStandardItem(tr(
"File")));
151 if(!m_pDetail->isChecked()) {
152 m_pTableView->hideColumn(3);
153 m_pTableView->hideColumn(m_nFileRow);
165 m_pTableView->horizontalHeader()->setSectionResizeMode(
166#
if defined(DEBUG) && !defined(Q_OS_ANDROID)
169 QHeaderView::Interactive);
176 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
177 QModelIndexList lstIndex;
179 lstIndex = pSelect->selectedRows();
180 if(m_pModel->rowCount() > 0 && lstIndex.isEmpty())
182 m_pTableView->selectRow(0);
187CFrmListRecentConnects::~CFrmListRecentConnects()
191void CFrmListRecentConnects::slotLoadFiles()
193 m_pModel->removeRows(0, m_pModel->rowCount());
194 QString szPath = RabbitCommon::CDir::Instance()->GetDirUserData();
196 QStringList files = dir.entryList(QStringList() <<
"*.rrc",
197 QDir::Files, QDir::Time);
198 foreach (
auto fileName, files) {
199 QString szFile = dir.absoluteFilePath(fileName);
200 if(szFile.isEmpty())
continue;
204 QList<QStandardItem*> lstItem;
205 QStandardItem* pName =
new QStandardItem(c->
Icon(), c->
Name());
208 QStandardItem* pProtocol =
new QStandardItem(c->
Protocol());
209 lstItem << pProtocol;
210 QFileInfo fi(szFile);
211 lstItem <<
new QStandardItem(fi.lastModified().toLocalTime().toString());
212 QStandardItem* pId =
new QStandardItem(c->
Id());
214 QStandardItem* pFile =
new QStandardItem(szFile);
216 m_pModel->appendRow(lstItem);
221 if(m_pModel->rowCount() > 0)
223 m_pConnect->setEnabled(
true);
224 m_pEditConnect->setEnabled(
true);
225 m_pEdit->setEnabled(
true);
226 m_pCopy->setEnabled(
true);
227 m_pDelete->setEnabled(
true);
229 m_pConnect->setEnabled(
false);
230 m_pEditConnect->setEnabled(
false);
231 m_pEdit->setEnabled(
false);
232 m_pCopy->setEnabled(
false);
233 m_pDelete->setEnabled(
false);
239 m_pTableView->resizeColumnToContents(0);
240 m_pTableView->resizeColumnToContents(1);
241 m_pTableView->resizeColumnToContents(2);
245int CFrmListRecentConnects::InsertItem(
CConnecter *c, QString& szFile)
247 QList<QStandardItem*> lstItem;
248 QStandardItem* pName =
new QStandardItem(c->
Icon(), c->
Name());
251 QStandardItem* pProtocol =
new QStandardItem(c->
Protocol());
252 lstItem << pProtocol;
253 QFileInfo fi(szFile);
254 lstItem <<
new QStandardItem(fi.lastModified().toString());
255 QStandardItem* pId =
new QStandardItem(c->
Id());
257 QStandardItem* pFile =
new QStandardItem(szFile);
259 m_pModel->insertRow(0, lstItem);
260 m_pTableView->selectRow(0);
267 QAction* pAction = m_pMenuNew->addAction(
269 this, SLOT(slotNew()));
272 pAction->setData(
id);
273 pAction->setIcon(pPlug->Icon());
277void CFrmListRecentConnects::slotNew()
279 QAction* pAction =
dynamic_cast<QAction*
>(this->sender());
281 if(
nullptr == c)
return;
286 case QDialog::Rejected:
288 case QDialog::Accepted:
290 QString szFile = c->GetSettingsFile();
292 if(d.exists(szFile)) {
293 QMessageBox::StandardButton r
294 = QMessageBox::warning(
296 tr(
"File of connecter is exists. whether to overwrite it? File: %1").arg(szFile),
297 QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No,
298 QMessageBox::StandardButton::No);
299 if(QMessageBox::StandardButton::Ok == r)
309 InsertItem(c, szFile);
318void CFrmListRecentConnects::slotEdit()
320 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
321 QModelIndexList lstIndex = pSelect->selectedRows();
322 foreach(
auto index, lstIndex)
324 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
329 case QDialog::Rejected:
331 case QDialog::Accepted:
339void CFrmListRecentConnects::slotEditConnect()
341 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
342 QModelIndexList lstIndex = pSelect->selectedRows();
343 foreach(
auto index, lstIndex)
345 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
350 case QDialog::Rejected:
352 case QDialog::Accepted:
354 emit sigConnect(szFile);
363void CFrmListRecentConnects::slotCopy()
365 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
366 QModelIndexList lstIndex = pSelect->selectedRows();
367 foreach(
auto index, lstIndex)
369 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
378 case QDialog::Rejected:
380 case QDialog::Accepted:
382 szFile = c->GetSettingsFile();
384 if(d.exists(szFile)) {
385 QMessageBox::StandardButton r
386 = QMessageBox::warning(
389 tr(
"File of connecter is exists. whether to overwrite it? "
390 "If select No, please modify the name of connecter"),
391 QMessageBox::StandardButton::Ok
392 | QMessageBox::StandardButton::No
393 | QMessageBox::StandardButton::Cancel,
394 QMessageBox::StandardButton::No);
395 if(QMessageBox::StandardButton::No == r)
400 if(QMessageBox::StandardButton::Cancel == r)
406 InsertItem(c, szFile);
419void CFrmListRecentConnects::slotDelete()
421 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
422 QModelIndexList lstIndex = pSelect->selectedRows();
423 foreach(
auto index, lstIndex)
425 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
428 m_pModel->removeRow(index.row());
432void CFrmListRecentConnects::slotConnect()
434 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
435 QModelIndexList lstIndex = pSelect->selectedRows();
436 foreach(
auto index, lstIndex)
438 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
439 emit sigConnect(szFile);
441 if(!m_bDock) close();
444void CFrmListRecentConnects::slotDetail()
446 if(m_pDetail->isChecked()) {
447 m_pTableView->showColumn(3);
448 m_pTableView->showColumn(m_nFileRow);
450 m_pTableView->hideColumn(3);
451 m_pTableView->hideColumn(m_nFileRow);
455void CFrmListRecentConnects::slotCustomContextMenu(
const QPoint &pos)
459 menu.addAction(QIcon::fromTheme(
"network-wired"),
460 tr(
"Connect"),
this, SLOT(slotConnect()));
461 menu.addAction(tr(
"Edit and Connect"),
this, SLOT(slotEditConnect()));
463 menu.addMenu(m_pMenuNew);
464 menu.addAction(tr(
"Edit"),
this, SLOT(slotEdit()));
465 menu.addAction(QIcon::fromTheme(
"edit-copy"), tr(
"Copy"),
466 this, SLOT(slotCopy()));
467 menu.addAction(QIcon::fromTheme(
"edit-delete"), tr(
"Delete"),
468 this, SLOT(slotDelete()));
470 menu.addAction(QIcon::fromTheme(
"view-refresh"), tr(
"Refresh"),
471 this, SLOT(slotLoadFiles()));
473 menu.exec(mapToGlobal(pos));
476void CFrmListRecentConnects::slotDoubleClicked(
const QModelIndex& index)
478 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
479 emit sigConnect(szFile);
480 if(!m_bDock) close();
manage plugins and connecter
virtual CConnecter * LoadConnecter(const QString &szFile)
New CConnecter pointer from file, the owner is caller.
virtual CConnecter * CreateConnecter(const QString &id)
New CConnecter pointer, the owner is caller.
virtual int DeleteConnecter(CConnecter *p)
Delete CConnecter.
virtual int SaveConnecter(CConnecter *pConnecter)
Accept connecter parameters to file.
virtual const QIcon Icon() const
Icon.
virtual int OpenDialogSettings(QWidget *parent=nullptr)
Open settings dialog.
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.
virtual const QString DisplayName() const
The plugin display name.
virtual const QString Description() const =0
Plugin description.
virtual const QString Protocol() const =0
Plugin Protocol.