Exemplo n.º 1
0
void
MainWindow::addTrackerToList(Backend *newTracker, bool sync)
{
    qDebug() << "Adding tracker to list";
    if (pDetectorProgress != NULL)
    {
        pDetectorProgress->reset();
        pDetectorProgress->hide();
    }

    connect(this, SIGNAL(reloadFromDatabase()),
            newTracker->displayWidget(), SLOT(reloadFromDatabase()));
    connect(this, SIGNAL(setShowOptions(bool,bool,bool,bool)),
            newTracker->displayWidget(), SLOT(setShowOptions(bool,bool,bool,bool)));
    connect(newTracker->displayWidget(), SIGNAL(bugChanged()),
            this, SLOT(toggleButtons()));
    int newIndex = ui->trackerTab->insertTab(0, newTracker->displayWidget(), newTracker->name());
    pSearchTab->addTracker(newTracker);
    filterTable();

    QString iconPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    iconPath.append(QDir::separator()).append("entomologist");
    iconPath.append(QDir::separator()).append(QString("%1.png").arg(newTracker->name()));
    ui->trackerTab->setTabIcon(newIndex, QIcon(iconPath));
    ui->trackerTab->setCurrentIndex(newIndex);
    mBackendMap[newTracker->id()] = newTracker;
    mBackendList.append(newTracker);
    if(!QFile::exists(iconPath))
        fetchIcon(newTracker->url(), iconPath, newTracker->username(), newTracker->password());
    if (sync)
        syncTracker(newTracker);
}
Exemplo n.º 2
0
/**
 * @brief MainWindow::openMap Initialize and opens the given map.
 * @param map
 * @param notify Notifies all the clients that a new map has been opened if true.
 */
void MainWindow::openMap(Map *map, bool notify) {
    QListWidget *tokenList = ui->tokenPage->getUi()->m_tokenList;

    // Initialize Map with the MapServer
    if (m_Server != NULL) {
        Receiver *mapServerReceiver = m_Server->getReceiver(TargetCode::MAP_SERVER);
        MapServer *mapServer = dynamic_cast<MapServer*>(mapServerReceiver);
        map->setSenderServer(mapServer);
    }

    // Initialize Map with the MapClient
    Receiver *mapClientReceiver = m_Client->getReceiver(TargetCode::MAP_CLIENT);
    MapClient *mapClient = dynamic_cast<MapClient*>(mapClientReceiver);
    mapClient->addMapToList(map);
    map->setSenderClient(mapClient);

    QMdiSubWindow *subwindow = ui->tableArea->addSubWindow(map);
    subwindow->show();
    subwindow->move(0, 0);

    connect(tokenList, SIGNAL(currentItemChanged(QListWidgetItem*,  QListWidgetItem *)),
            map->getMapLayer(), SLOT(setTokenItem(QListWidgetItem*))
    );

    if (notify) {
        // Notifies all the clients that a new map has been opened
        Receiver *mapClientReceiver = m_Client->getReceiver(TargetCode::MAP_CLIENT);
        MapClient *mapClient = dynamic_cast<MapClient*>(mapClientReceiver);
        QString msg = QString("%1").arg(map->id());
        mapClient->sendMessageToServer(msg, (quint16) MapCodes::OPEN_MAP);
    }

    m_NotificationStacker.pushNotification("Une carte a été ouverte");

    // Connect to the LogClient
    TargetCode logClientCode(TargetCode::LOGGER_CLIENT);
    Receiver *logClientReceiver = m_Client->getReceiver(logClientCode);
    LogClient *logClient = dynamic_cast<LogClient*>(logClientReceiver);
    map->connectToLogger(logClient);
}