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(QIcon::fromTheme(
"network-wired"), tr(
"Connect"),
28 this, SLOT(slotConnect()));
29 m_pConnect->setStatusTip(tr(
"Connect"));
30 m_pConnect->setToolTip(tr(
"Connect"));
31 m_pEditConnect = m_pToolBar->addAction(tr(
"Edit and Connect"),
32 this, SLOT(slotEditConnect()));
33 m_pEditConnect->setStatusTip(tr(
"Edit and Connect"));
34 m_pEditConnect->setToolTip(tr(
"Edit and Connect"));
35 m_pToolBar->addSeparator();
37 m_ptbConnect =
new QToolButton(m_pToolBar);
38 m_ptbConnect->setFocusPolicy(Qt::NoFocus);
39 m_ptbConnect->setPopupMode(QToolButton::InstantPopup);
41 m_pMenuNew =
new QMenu(tr(
"New"),
this);
42 m_pMenuNew->setIcon(QIcon::fromTheme(
"add"));
43 m_ptbConnect->setMenu(m_pMenuNew);
44 m_ptbConnect->setIcon(m_pMenuNew->icon());
45 m_ptbConnect->setText(tr(
"New"));
46 m_ptbConnect->setToolTip(tr(
"New"));
47 m_ptbConnect->setStatusTip(tr(
"New"));
48 m_pToolBar->addWidget(m_ptbConnect);
49 m_pClient->EnumPlugins(
this);
50 m_pEdit = m_pToolBar->addAction(QIcon::fromTheme(
"edit"), tr(
"Edit"),
51 this, SLOT(slotEdit()));
52 m_pEdit->setStatusTip(tr(
"Edit"));
53 m_pEdit->setToolTip(tr(
"Edit"));
54 m_pCopy = m_pToolBar->addAction(QIcon::fromTheme(
"edit-copy"), tr(
"Copy"),
55 this, SLOT(slotCopy()));
56 m_pCopy->setStatusTip(tr(
"Copy"));
57 m_pCopy->setToolTip(tr(
"Copy"));
58 m_pDelete = m_pToolBar->addAction(
59 QIcon::fromTheme(
"edit-delete"), tr(
"Delete"),
60 this, SLOT(slotDelete()));
61 m_pDelete->setToolTip(tr(
"Delete"));
62 m_pDelete->setStatusTip(tr(
"Delete"));
63 m_pDetail = m_pToolBar->addAction(
64 QIcon::fromTheme(
"dialog-information"), tr(
"Detail"),
65 this, SLOT(slotDetail()));
66 m_pDetail->setCheckable(
true);
67 m_pDetail->setChecked(
false);
68 m_pDetail->setToolTip(tr(
"Detail"));
69 m_pDetail->setStatusTip(tr(
"Detail"));
70 m_pToolBar->addSeparator();
72 m_pRefresh = m_pToolBar->addAction(
73 QIcon::fromTheme(
"view-refresh"),
75 this, SLOT(slotLoadFiles()));
76 m_pRefresh->setToolTip(tr(
"Refresh"));
77 m_pRefresh->setStatusTip(tr(
"Refresh"));
79 QAction* pClose = m_pToolBar->addAction(
80 QIcon::fromTheme(
"window-close"), tr(
"Close"),
82 pClose->setStatusTip(tr(
"Close"));
83 pClose->setToolTip(tr(
"Close"));
86 layout()->addWidget(m_pToolBar);
89 m_pDockTitleBar =
new RabbitCommon::CTitleBar(parent);
91 QMenu* pMenu =
new QMenu(tr(
"Tools"), m_pDockTitleBar);
92 QPushButton* pTools = m_pDockTitleBar->CreateSmallPushButton(
93 QIcon::fromTheme(
"tools"), m_pDockTitleBar);
94 pTools->setToolTip(tr(
"Tools"));
95 pTools->setMenu(pMenu);
96 QList<QWidget*> lstWidget;
98 m_pDockTitleBar->AddWidgets(lstWidget);
100 pMenu->addAction(m_pConnect);
101 pMenu->addAction(m_pEditConnect);
102 pMenu->addMenu(m_pMenuNew);
103 pMenu->addAction(m_pEdit);
104 pMenu->addAction(m_pCopy);
105 pMenu->addAction(m_pDelete);
106 pMenu->addAction(m_pDetail);
107 pMenu->addAction(m_pRefresh);
111 m_pTableView =
new QTableView(
this);
112 m_pTableView->setContextMenuPolicy(Qt::CustomContextMenu);
113 bool check = connect(m_pTableView,
114 SIGNAL(customContextMenuRequested(
const QPoint &)),
115 this, SLOT(slotCustomContextMenu(
const QPoint &)));
117 check = connect(m_pTableView, SIGNAL(doubleClicked(
const QModelIndex &)),
118 this, SLOT(slotDoubleClicked(
const QModelIndex&)));
120 layout()->addWidget(m_pTableView);;
122 m_pModel =
new QStandardItemModel(m_pTableView);
123 m_pTableView->setModel(m_pModel);
124 m_pTableView->verticalHeader()->hide();
125 m_pTableView->setSelectionMode(QAbstractItemView::SingleSelection);
126 m_pTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
127 m_pTableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
128 m_pModel->setHorizontalHeaderItem(0,
new QStandardItem(tr(
"Name")));
129 m_pModel->setHorizontalHeaderItem(1,
new QStandardItem(tr(
"Protocol")));
130 m_pModel->setHorizontalHeaderItem(2,
new QStandardItem(tr(
"Date")));
131 m_pModel->setHorizontalHeaderItem(3,
new QStandardItem(tr(
"ID")));
133 m_pModel->setHorizontalHeaderItem(m_nFileRow,
new QStandardItem(tr(
"File")));
134 if(!m_pDetail->isChecked()) {
135 m_pTableView->hideColumn(3);
136 m_pTableView->hideColumn(m_nFileRow);
148 m_pTableView->horizontalHeader()->setSectionResizeMode(
149 #
if defined(DEBUG) && !defined(Q_OS_ANDROID)
152 QHeaderView::ResizeToContents);
159 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
160 QModelIndexList lstIndex;
162 lstIndex = pSelect->selectedRows();
163 if(m_pModel->rowCount() > 0 && lstIndex.isEmpty())
165 m_pTableView->selectRow(0);
170CFrmListConnects::~CFrmListConnects()
174void CFrmListConnects::slotLoadFiles()
176 m_pModel->removeRows(0, m_pModel->rowCount());
177 QString szPath = RabbitCommon::CDir::Instance()->GetDirUserData();
179 QStringList files = dir.entryList(QStringList() <<
"*.rrc",
180 QDir::Files, QDir::Time);
181 foreach (
auto fileName, files) {
182 QString szFile = dir.absoluteFilePath(fileName);
183 if(szFile.isEmpty())
continue;
187 QList<QStandardItem*> lstItem;
188 QStandardItem* pName =
new QStandardItem(c->
Icon(), c->
Name());
191 QStandardItem* pProtocol =
new QStandardItem(c->
Protocol());
192 lstItem << pProtocol;
193 QFileInfo fi(szFile);
194 lstItem <<
new QStandardItem(fi.lastModified().toLocalTime().toString());
195 QStandardItem* pId =
new QStandardItem(c->
Id());
197 QStandardItem* pFile =
new QStandardItem(szFile);
199 m_pModel->appendRow(lstItem);
204 if(m_pModel->rowCount() > 0)
206 m_pConnect->setEnabled(
true);
207 m_pEditConnect->setEnabled(
true);
208 m_pEdit->setEnabled(
true);
209 m_pCopy->setEnabled(
true);
210 m_pDelete->setEnabled(
true);
212 m_pConnect->setEnabled(
false);
213 m_pEditConnect->setEnabled(
false);
214 m_pEdit->setEnabled(
false);
215 m_pCopy->setEnabled(
false);
216 m_pDelete->setEnabled(
false);
222int CFrmListConnects::InsertItem(
CConnecter *c, QString& szFile)
224 QList<QStandardItem*> lstItem;
225 QStandardItem* pName =
new QStandardItem(c->
Icon(), c->
Name());
228 QStandardItem* pProtocol =
new QStandardItem(c->
Protocol());
229 lstItem << pProtocol;
230 QFileInfo fi(szFile);
231 lstItem <<
new QStandardItem(fi.lastModified().toString());
232 QStandardItem* pId =
new QStandardItem(c->
Id());
234 QStandardItem* pFile =
new QStandardItem(szFile);
236 m_pModel->insertRow(0, lstItem);
237 m_pTableView->selectRow(0);
244 QAction* pAction = m_pMenuNew->addAction(pPlug->
Protocol()
246 this, SLOT(slotNew()));
249 pAction->setData(
id);
250 pAction->setIcon(pPlug->Icon());
254void CFrmListConnects::slotNew()
256 QAction* pAction =
dynamic_cast<QAction*
>(this->sender());
258 if(
nullptr == c)
return;
263 case QDialog::Rejected:
265 case QDialog::Accepted:
267 QString szFile = RabbitCommon::CDir::Instance()->GetDirUserData()
272 if(d.exists(szFile)) {
273 QMessageBox::StandardButton r
274 = QMessageBox::warning(
this, tr(
"Warning"),
275 tr(
"File of connecter is exists. whether to overwrite it? File: %1").arg(szFile),
276 QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No,
277 QMessageBox::StandardButton::No);
278 if(QMessageBox::StandardButton::Ok == r)
288 InsertItem(c, szFile);
297void CFrmListConnects::slotEdit()
299 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
300 QModelIndexList lstIndex = pSelect->selectedRows();
301 foreach(
auto index, lstIndex)
303 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
308 case QDialog::Rejected:
310 case QDialog::Accepted:
318void CFrmListConnects::slotEditConnect()
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:
333 emit sigConnect(szFile);
342void CFrmListConnects::slotCopy()
344 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
345 QModelIndexList lstIndex = pSelect->selectedRows();
346 foreach(
auto index, lstIndex)
348 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
357 case QDialog::Rejected:
359 case QDialog::Accepted:
361 szFile = RabbitCommon::CDir::Instance()->GetDirUserData()
366 if(d.exists(szFile)) {
367 QMessageBox::StandardButton r = QMessageBox::warning(
this,
369 tr(
"File of connecter is exists. whether to overwrite it? "
370 "If select No, please modify the name of connecter"),
371 QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No | QMessageBox::StandardButton::Cancel,
372 QMessageBox::StandardButton::No);
373 if(QMessageBox::StandardButton::No == r)
378 if(QMessageBox::StandardButton::Cancel == r)
384 InsertItem(c, szFile);
397void CFrmListConnects::slotDelete()
399 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
400 QModelIndexList lstIndex = pSelect->selectedRows();
401 foreach(
auto index, lstIndex)
403 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
406 m_pModel->removeRow(index.row());
410void CFrmListConnects::slotConnect()
412 QItemSelectionModel* pSelect = m_pTableView->selectionModel();
413 QModelIndexList lstIndex = pSelect->selectedRows();
414 foreach(
auto index, lstIndex)
416 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
417 emit sigConnect(szFile);
419 if(!m_bDock) close();
422void CFrmListConnects::slotDetail()
424 if(m_pDetail->isChecked()) {
425 m_pTableView->showColumn(3);
426 m_pTableView->showColumn(m_nFileRow);
428 m_pTableView->hideColumn(3);
429 m_pTableView->hideColumn(m_nFileRow);
433void CFrmListConnects::slotCustomContextMenu(
const QPoint &pos)
437 menu.addAction(QIcon::fromTheme(
"network-wired"), tr(
"Connect"),
this, SLOT(slotConnect()));
438 menu.addAction(tr(
"Edit and Connect"),
this, SLOT(slotEditConnect()));
440 menu.addMenu(m_pMenuNew);
441 menu.addAction(tr(
"Edit"),
this, SLOT(slotEdit()));
442 menu.addAction(QIcon::fromTheme(
"edit-copy"), tr(
"Copy"),
this, SLOT(slotCopy()));
443 menu.addAction(QIcon::fromTheme(
"edit-delete"), tr(
"Delete"),
this, SLOT(slotDelete()));
445 menu.addAction(QIcon::fromTheme(
"view-refresh"), tr(
"Refresh"),
this, SLOT(slotLoadFiles()));
447 menu.exec(mapToGlobal(pos));
450void CFrmListConnects::slotDoubleClicked(
const QModelIndex& index)
452 QString szFile = m_pModel->item(index.row(), m_nFileRow)->text();
453 emit sigConnect(szFile);
454 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 SaveConnecter(QString szFile, 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.