| 37 | } |
| 38 | |
| 39 | int COperateWakeOnLan::Initial() |
| 40 | { |
| 41 | int nRet = COperate::Initial(); |
| 42 | if(nRet) return nRet; |
| 43 | qDebug(log) << Q_FUNC_INFO; |
| 44 | bool check = false; |
| 45 | CPlugin* plugin = GetPlugin(); |
| 46 | m_pModel = new CWakeOnLanModel(this); |
| 47 | if(!m_pModel) |
| 48 | return -1; |
| 49 | m_pView = new CFrmWakeOnLan(m_pModel); |
| 50 | if(!m_pView) return -1; |
| 51 | QToolBar* pToolBar = m_pView->GetToolBar(); |
| 52 | if(!pToolBar) return -1; |
| 53 | m_pView->setWindowTitle(plugin->Name()); |
| 54 | |
| 55 | check = connect(m_pView, SIGNAL(sigViewerFocusIn(QWidget*)), |
| 56 | this, SIGNAL(sigViewerFocusIn(QWidget*))); |
| 57 | Q_ASSERT(check); |
| 58 | check = connect(m_pView, &CFrmWakeOnLan::customContextMenuRequested, |
| 59 | this, [&](const QPoint &pos){ |
| 60 | m_Menu.exec(m_pView->mapToGlobal(pos)); |
| 61 | }); |
| 62 | Q_ASSERT(check); |
| 63 | |
| 64 | m_Menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy ip address to clipbord"), |
| 65 | this, [&](){ |
| 66 | if(!m_pModel || !m_pView) |
| 67 | return; |
| 68 | foreach(auto index, m_pView->GetSelect()) { |
| 69 | QSharedPointer<CParameterWakeOnLan> p = m_pModel->GetData(index); |
| 70 | if(!p) continue; |
| 71 | QString szIp = p->m_Net.GetHost(); |
| 72 | if(szIp.isEmpty()) continue; |
| 73 | QApplication::clipboard()->setText(szIp); |
| 74 | } |
| 75 | }); |
| 76 | m_Menu.addSeparator(); |
| 77 | |
| 78 | QAction* pRefresh = m_Menu.addAction(QIcon::fromTheme("view-refresh"), tr("Refresh"), |
| 79 | this, [&](){ |
| 80 | foreach(auto p, m_pModel->m_Data) |
| 81 | m_Arp.GetMac(p); |
| 82 | }); |
| 83 | pToolBar->addAction(pRefresh); |
| 84 | QAction* pMac = m_Menu.addAction( |
| 85 | QIcon::fromTheme("mac"), tr("Get mac address"), |
| 86 | this, [&](){ |
| 87 | if(!m_pModel || !m_pView) |
| 88 | return; |
| 89 | foreach(auto index, m_pView->GetSelect()) { |
| 90 | QSharedPointer<CParameterWakeOnLan> p = m_pModel->GetData(index); |
| 91 | if(!p) continue; |
| 92 | if(m_Arp.GetMac(p)) |
| 93 | p->SetHostState(CParameterWakeOnLan::HostState::GetMac); |
| 94 | } |
| 95 | }); |
| 96 | pToolBar->addAction(pMac); |
nothing calls this directly
no test coverage detected