Esempio n. 1
0
MainWindow::MainWindow(std::unique_ptr<Application> app):
    app_(std::move(app)),
    ui(new Ui::MainWindow),
    current_search_(nullptr),
    search_count_(0),
    auto_online_(app_->data_manager(), app_->sensitive_data_manager())
{
#ifdef Q_OS_WIN32
    createWinId();
    taskbar_button_ = new QWinTaskbarButton(this);
    taskbar_button_->setWindow(this->windowHandle());
#endif
    image_cache_ = new ImageCache(Filesystem::UserDir() + "/cache");

    InitializeUi();
    InitializeLogging();
    InitializeSearchForm();
    NewSearch();

    image_network_manager_ = new QNetworkAccessManager;
    connect(image_network_manager_, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(OnImageFetched(QNetworkReply*)));

    connect(&app_->items_manager(), SIGNAL(ItemsRefreshed(Items, std::vector<std::string>)),
        this, SLOT(OnItemsRefreshed()));
    connect(&app_->items_manager(), SIGNAL(StatusUpdate(ItemsFetchStatus)), this, SLOT(OnItemsManagerStatusUpdate(ItemsFetchStatus)));
    connect(&update_checker_, &UpdateChecker::UpdateAvailable, this, &MainWindow::OnUpdateAvailable);
    connect(&auto_online_, &AutoOnline::Update, this, &MainWindow::OnOnlineUpdate);
}
void ItemsManagerWorker::StatusFinished() {
    CurrentStatusUpdate status = CurrentStatusUpdate();
    status.state = ProgramState::ItemsCompleted;
    status.progress = 100;
    status.total = 100;
    emit StatusUpdate(status);
}
Esempio n. 3
0
void StatusUpdateFPS(BOOL bShow, int nSpeed, int nFPS, int nMachineFPS, int nFrameskip, int nVecUPS)
{
    char buf[100];
    uclock_t now;
    
    if (hStatus == NULL)
        return;
    
    if (MAME32App.m_bMamePaused || MAME32App.m_bAutoPaused)
    {
        StatusUpdate();
        return;
    }

    if (bShow == FALSE)
    {
        SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)"");
        return;
    }

    now = uclock();
    
    /* update twice a second or so */
    if ((now - prev_update_time) < (UCLOCKS_PER_SEC/2))
        return;
    
    sprintf(buf, "\t\tfskp%2d%4d%%%4d/%d fps", nFrameskip, nSpeed, nFPS, nMachineFPS);
    
    SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)buf);
    
    prev_update_time = now;
}
void ItemsManagerWorker::Update() {
    if (updating_) {
        QLOG_WARN() << "ItemsManagerWorker::Update called while updating";
        return;
    }

    QLOG_INFO() << "Updating stash tabs";
    updating_ = true;
    // remove all mappings (from previous requests)
    if (signal_mapper_)
        delete signal_mapper_;
    signal_mapper_ = new QSignalMapper;
    // remove all pending requests
    queue_ = std::queue<ItemsRequest>();
    queue_id_ = 0;
    replies_.clear();
    items_.clear();
    tabs_as_string_ = "";
    items_as_string_ = "[ "; // space here is important, see ParseItems and OnTabReceived when all requests are completed
    selected_character_ = "";

    CurrentStatusUpdate status = CurrentStatusUpdate();
    status.state = ProgramState::ItemsUpdating;
    status.progress = 0;
    status.total = 100;
    emit StatusUpdate(status);

    // first, download the main page because it's the only way to know which character is selected
    QNetworkReply *main_page = network_manager_.get(QNetworkRequest(QUrl(kMainPage)));
    connect(main_page, &QNetworkReply::finished, this, &ItemsManagerWorker::OnMainPageReceived);
}
void VlcVideoWidget::StatusPoller()
{
    if (statusAccess.tryLock())
    {
        if (status.doStop)
        {
            Stop();
            libvlc_media_player_release(vlcPlayer_);
            status.doStop = false;
        }
        else if (status.doRestart && !status.playing)
        {
            RestartPlayback();
            status.doRestart = false;
        }

        // Emit a status update if there is one
        if (status.change != PlayerStatus::NoChange)
        {
            emit StatusUpdate(status);
            status.change = PlayerStatus::NoChange;
        }

        statusAccess.unlock();
    }
}
Esempio n. 6
0
void MainWindow::FeedCell(int row, int column, bool life)
{
    QTableWidgetItem * item = LifeField->item(row, column);


    if(item == 0)
    {
        item = new QTableWidgetItem;
        LifeField->setItem(row, column, item);

    }
    if(life == true)
    {
        ItemPopulated(item);
        LifeCount++;
    }
else
    {
        ItemEmpty(item);
        LifeCount--;
    }


    emit StatusUpdate(LifeCount, IterationCount);

}
Esempio n. 7
0
void MainWindow::FeedCell(int row, int column)
{
    QTableWidgetItem * item = LifeField->item(row, column);
    bool populated;

    if(item == 0)
    {
        item = new QTableWidgetItem;
        LifeField->setItem(row, column, item);
        populated= false;
    }
    else populated= item->data(Qt::UserRole).toBool();

    if(populated == true)
    {
        ItemEmpty(item);
        --LifeCount;
    }
    else
    {
        ItemPopulated(item);        
        ++LifeCount;
    }

    emit StatusUpdate(LifeCount, IterationCount);
    emit CellsChanged(row, column, !populated);

}
Esempio n. 8
0
void MainWindow::ColumnsChanged()
{
    if(LifeField->columnCount() == ColumnChanger->value()) return;

    int oldColumns = LifeField->columnCount();
    int lifeCropped = 0;
    QTableWidgetItem *item;

    //gdy kolumn jest mniej
    for(int i=ColumnChanger->value(); i< oldColumns; i++)
    {
        for(int j=0; j< LifeField->rowCount();j++)
        {
            item = LifeField->item(j,i);
            if(item == 0) continue;
            if(item->data(Qt::UserRole)== true) ++lifeCropped;
        }
    }
    if(lifeCropped > 0) emit StatusUpdate((LifeCount - lifeCropped), IterationCount);

    LifeField->setColumnCount(ColumnChanger->value());

    //Gdy wierszy jest więcej
    for( int i = oldColumns; i< ColumnChanger->value();i++)
    {
        LifeField->setColumnWidth(i,10);
    }

    emit CellsChanged(LifeField->rowCount(),LifeField->columnCount());

}
Esempio n. 9
0
void ItemsManager::Start() {
    thread_ = std::make_unique<QThread>();
    worker_ = std::make_unique<ItemsManagerWorker>(app_, thread_.get());
    connect(thread_.get(), SIGNAL(started()), worker_.get(), SLOT(Init()));
    connect(this, SIGNAL(UpdateSignal()), worker_.get(), SLOT(Update()));
    connect(worker_.get(), SIGNAL(StatusUpdate(ItemsFetchStatus)), this, SLOT(OnStatusUpdate(ItemsFetchStatus)));
    connect(worker_.get(), SIGNAL(ItemsRefreshed(Items, std::vector<std::string>)), this, SLOT(OnItemsRefreshed(Items, std::vector<std::string>)));
    worker_->moveToThread(thread_.get());
    thread_->start();
}
Esempio n. 10
0
/*
    Update the display.
*/
static void GDI_update_display(void)
{
    if (This.m_bUpdatePalette == TRUE)
    {
        SetPaletteColors();
        This.m_bUpdatePalette = FALSE;
    }

    InvalidateRect(MAME32App.m_hWnd, &This.m_ClientRect, FALSE);

    UpdateWindow(MAME32App.m_hWnd);

    StatusUpdate();

    MAME32App.ProcessMessages();
}
Esempio n. 11
0
void QueueManager::SetStatus(QueueManagerStatus status)
{
    QMutexLocker locker(&m_mutexStatus);
    if (m_status == status)
    {
        Logger::Log(DEBUG, "QueueManager SetStatus: no change");
        return;
    }

    m_status = status;
    locker.unlock();

    Logger::Log(INFO, "Queue Manager : %s", qPrintable(StatusToStr(status)));

    // notify engine & its clients of status change :
    emit StatusUpdate(StatusToStr(status));
}
Esempio n. 12
0
void Shop::SubmitSingleShop() {
    CurrentStatusUpdate status = CurrentStatusUpdate();
    status.state = ProgramState::ShopSubmitting;
    status.progress = requests_completed_;
    status.total = threads_.size();
    if (requests_completed_ == threads_.size()) {
        status.state = ProgramState::ShopCompleted;
        submitting_ = false;
        app_.data().Set("shop_hash", shop_hash_);
    } else {
        // first, get to the edit-thread page to grab CSRF token
        QNetworkReply *fetched = app_.logged_in_nm().get(QNetworkRequest(QUrl(ShopEditUrl(requests_completed_).c_str())));
        new QReplyTimeout(fetched, kEditThreadTimeout);
        connect(fetched, SIGNAL(finished()), this, SLOT(OnEditPageFinished()));
    }
    emit StatusUpdate(status);
}
Esempio n. 13
0
void
DeleteConnection(Connection *conn)
{
    MemPool *mpool = conn->co_MemPool;

    if (conn->co_Desc->d_Type == THREAD_SPOOL) {
	conn->co_LastServerLog = 1;
	LogServerInfo(conn, TFd);
    } else if (conn->co_Desc->d_Type == THREAD_NNTP) {
	char statbuf[1024];
	char vsbuf[11];
	char hsbuf[31];

	snprintf(vsbuf, sizeof(vsbuf), "%s", conn->co_Auth.dr_VServerDef->vs_Name);

	snprintf(hsbuf, sizeof(hsbuf), "%s%s%s%s%s",
		*conn->co_Auth.dr_AuthUser ? conn->co_Auth.dr_AuthUser : "",
		*conn->co_Auth.dr_AuthUser ? "/" : "",
		*conn->co_Auth.dr_IdentUser ? conn->co_Auth.dr_IdentUser : "",
		*conn->co_Auth.dr_IdentUser ? "@" : "",
		conn->co_Auth.dr_Host);
	RTStatusBase(conn->co_Desc->d_Slot, "CLSD %-10s %-30s", vsbuf, hsbuf);

	GroupStats(conn);

	snprintf(statbuf, sizeof(statbuf), "exit articles %lu groups %lu posts %lu bytes %.0f", conn->co_ClientTotalArticleCount, conn->co_ClientGroupCount, conn->co_ClientPostCount, conn->co_ClientTotalByteCount);
	LogCmd(conn, '$', statbuf);

	StatusUpdate(conn, "(closed)");
	freeReaderSlot(conn->co_Desc->d_Slot);
	--NumReaders;
	/*
	 * Inform the main server that we are done with the descriptor
	 * by writing the DnsRes structure back to it, so the main server
	 * can track who from where is connecting to what and when that
	 * connection terminates.
	 */
	conn->co_Auth.dr_ByteCount = conn->co_TMBuf.mh_TotalBytes;
	SendMsg(TFd, conn->co_Desc->d_Fd, &conn->co_Auth);
    }

    FreeControl(conn);
    freePool(&conn->co_BufPool);
    freePool(&mpool);		/* includes Connection structure itself */
}
Esempio n. 14
0
//*****************************************************************************
//
// Displays the "VComp Control Mode" panel.  The returned valud is the ID of
// the panel to be displayed instead of the "VComp Control Mode" panel.
//
//*****************************************************************************
unsigned long
DisplayVComp(void)
{
    unsigned long ulRamp, ulComp, ulPos, ulIdx, ulDelay, ulDemo, ulTime;
    unsigned long ulStep;
    long lVoltage;

    //
    // Enable voltage compensation control mode.
    //
    CANVCompModeEnable();

    //
    // Set the default voltage.
    //
    lVoltage = 0;
    CANVCompSet(0, 0);

    //
    // Read the ramp rate.
    //
    if(CANReadParameter(LM_API_VCOMP_IN_RAMP, 0, &ulRamp, 0) == 0)
    {
        ulRamp = 0;
    }
    else
    {
        ulRamp = (((ulRamp & 0xffff) * 100) + 128) / 256;
    }

    //
    // Read the compensation rate.
    //
    if(CANReadParameter(LM_API_VCOMP_COMP_RAMP, 0, &ulComp, 0) == 0)
    {
        ulComp = 0;
    }
    else
    {
        ulComp = (((ulComp & 0xffff) * 100) + 128) / 256;
    }

    //
    // Initially, updates to the voltage occur immediately.
    //
    ulDelay = 0;

    //
    // Initially, demo mode is disabled.
    //
    ulDemo = 0;
    ulTime = 0;
    ulStep = 0;

    //
    // Disable the widget fill for all the widgets except the one for the
    // device ID selection.
    //
    for(ulIdx = 0; ulIdx < 4; ulIdx++)
    {
        CanvasFillOff(g_psVCompWidgets + ulIdx);
    }
    CanvasFillOn(g_psVCompWidgets + 1);

    //
    // Add the "VComp Control Mode" panel widgets to the widget list.
    //
    for(ulIdx = 0; ulIdx < NUM_WIDGETS; ulIdx++)
    {
        WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psVCompWidgets + ulIdx));
    }

    //
    // Enable the status display.
    //
    StatusEnable(0);

    //
    // Set the default cursor position to the device ID selection.
    //
    ulPos = 1;

    //
    // Loop forever.  This loop will be explicitly exited when the proper
    // condition is detected.
    //
    while(1)
    {
        //
        // Print out the current device ID.
        //
        usnprintf(g_pcIDBuffer, sizeof(g_pcIDBuffer), "%d", g_ulCurrentID);

        //
        // Print out the current voltage.
        //
        if(lVoltage < 0)
        {
            usnprintf(g_pcVoltageBuffer, sizeof(g_pcVoltageBuffer),
                      "-%d.%01d V", (0 - lVoltage) / 10, (0 - lVoltage) % 10);
        }
        else
        {
            usnprintf(g_pcVoltageBuffer, sizeof(g_pcVoltageBuffer),
                      "%d.%01d V", lVoltage / 10, lVoltage % 10);
        }

        //
        // Print out the current ramp rate.
        //
        if(ulRamp == 0)
        {
            usnprintf(g_pcRampBuffer, sizeof(g_pcRampBuffer), "none");
        }
        else
        {
            usnprintf(g_pcRampBuffer, sizeof(g_pcRampBuffer), "%d.%02d V/ms",
                      ulRamp / 100, ulRamp % 100);
        }

        //
        // Print out the current compensation rate.
        //
        if(ulComp == 0)
        {
            usnprintf(g_pcCompBuffer, sizeof(g_pcCompBuffer), "none");
        }
        else
        {
            usnprintf(g_pcCompBuffer, sizeof(g_pcCompBuffer), "%d.%02d V/ms",
                      ulComp / 100, ulComp % 100);
        }

        //
        // Update the status display.
        //
        StatusUpdate();

        //
        // Update the display.
        //
        DisplayFlush();

        //
        // See if a serial download has begun.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_SERIAL_BOOTLOADER) == 1)
        {
            //
            // Disable the status display.
            //
            StatusDisable();

            //
            // Remove the "VComp Control Mode" panel widgets.
            //
            for(ulIdx = 0; ulIdx < NUM_WIDGETS; ulIdx++)
            {
                WidgetRemove((tWidget *)(g_psVCompWidgets + ulIdx));
            }
            CanvasTextColorSet(g_psVCompWidgets + 2, ClrWhite);

            //
            // Set the output voltage to zero.
            //
            CANVCompSet(0, 0);

            //
            // Return the ID of the update panel.
            //
            return(PANEL_UPDATE);
        }

        //
        // See if demo mode is enabled.
        //
        if(ulDemo != 0)
        {
            //
            // See if the current time delay has expired.
            //
            if(ulTime < g_ulTickCount)
            {
                //
                // Increment to the next step, wrapping back to the beginning
                // of the sequence when the end has been reached.
                //
                ulStep++;
                if(ulStep ==
                   (sizeof(g_plVCompDemo) / sizeof(g_plVCompDemo[0])))
                {
                    ulStep = 0;
                }

                //
                // Set the voltage as directed by the next step.
                //
                lVoltage = g_plVCompDemo[ulStep][0];
                CANVCompSet((lVoltage * 256) / 10, 0);

                //
                // Set the time delay for this step.
                //
                ulTime = g_ulTickCount + g_plVCompDemo[ulStep][1];
            }
        }

        //
        // See if the up button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_UP_PRESSED) == 1)
        {
            //
            // Only move the cursor if it is not already at the top of the
            // screen and a delayed voltage update is not in progress.
            //
            if((ulPos != 0) && (ulDelay == 0))
            {
                //
                // Disable the widget fill for the currently selected widget.
                //
                CanvasFillOff(g_psVCompWidgets + ulPos);

                //
                // Decrement the cursor row, skipping the voltage row when demo
                // mode is enabled.
                //
                ulPos--;
                if((ulPos == 2) && (ulDemo != 0))
                {
                    ulPos--;
                }

                //
                // Enable the widget fill for the newly selected widget.
                //
                CanvasFillOn(g_psVCompWidgets + ulPos);
            }

            //
            // Clear the press flag for the up button.
            //
            HWREGBITW(&g_ulFlags, FLAG_UP_PRESSED) = 0;
        }

        //
        // See if the down button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_DOWN_PRESSED) == 1)
        {
            //
            // Only move the cursor if it is not already at the bottom of the
            // screen and a delayed voltage update is not in progress.
            //
            if((ulPos != 4) && (ulDelay == 0))
            {
                //
                // Disable the widget fill for the currently selected widget.
                //
                CanvasFillOff(g_psVCompWidgets + ulPos);

                //
                // Increment the cursor row, skipping the voltage row when demo
                // mode is enabled.
                //
                ulPos++;
                if((ulPos == 2) && (ulDemo != 0))
                {
                    ulPos++;
                }

                //
                // Enable the widget fill for the newly selected widget.
                //
                CanvasFillOn(g_psVCompWidgets + ulPos);
            }

            //
            // Clear the press flag for the down button.
            //
            HWREGBITW(&g_ulFlags, FLAG_DOWN_PRESSED) = 0;
        }

        //
        // See if the left button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_LEFT_PRESSED) == 1)
        {
            //
            // See if the device ID is being changed.
            //
            if(ulPos == 1)
            {
                //
                // Only change the device ID if it is greater than one.
                //
                if(g_ulCurrentID > 1)
                {
                    //
                    // Exit demo mode.
                    //
                    ulDemo = 0;
                    CanvasTextColorSet(g_psVCompWidgets + 2, ClrWhite);

                    //
                    // Set the voltage to 0 for the current device ID.
                    //
                    CANVCompSet(0, 0);

                    //
                    // Decrement the device ID.
                    //
                    if((HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1))
                    {
                        if(g_ulCurrentID > 3)
                        {
                            CANSetID(g_ulCurrentID - 3);
                        }
                        else
                        {
                            CANSetID(1);
                        }
                    }
                    else
                    {
                        CANSetID(g_ulCurrentID - 1);
                    }

                    //
                    // Enable voltage compensation mode.
                    //
                    CANVCompModeEnable();

                    //
                    // Set the voltage for the new device.
                    //
                    lVoltage = 0;
                    CANVCompSet(0, 0);

                    //
                    // Read the ramp rate.
                    //
                    if(CANReadParameter(LM_API_VCOMP_IN_RAMP, 0, &ulRamp,
                                        0) == 0)
                    {
                        ulRamp = 0;
                    }
                    else
                    {
                        ulRamp = (((ulRamp & 0xffff) * 100) + 128) / 256;
                    }

                    //
                    // Read the compensation rate.
                    //
                    if(CANReadParameter(LM_API_VCOMP_COMP_RAMP, 0, &ulComp,
                                        0) == 0)
                    {
                        ulComp = 0;
                    }
                    else
                    {
                        ulComp = (((ulComp & 0xffff) * 100) + 128) / 256;
                    }
                }
            }

            //
            // See if the voltage is being changed.
            //
            else if(ulPos == 2)
            {
                //
                // Only change the voltage if it is not already full reverse.
                //
                if(lVoltage > -120)
                {
                    //
                    // Decrement the voltage.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1)
                    {
                        lVoltage -= 11;
                    }
                    else if((HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1) ||
                            (HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1))
                    {
                        lVoltage -= 111;
                    }
                    else
                    {
                        lVoltage--;
                    }
                    if(lVoltage < -120)
                    {
                        lVoltage = -120;
                    }

                    //
                    // Send the updated voltage to the motor controller if a
                    // delayed update is not in progress.
                    //
                    if(ulDelay == 0)
                    {
                        CANVCompSet((lVoltage * 256) / 10, 0);
                    }
                }
            }

            //
            // See if the voltage ramp rate is being changed.
            //
            else if(ulPos == 3)
            {
                //
                // Only change the ramp rate if it is not already zero.
                //
                if(ulRamp > 0)
                {
                    //
                    // Decrement the voltage ramp rate.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1)
                    {
                        ulRamp -= 11;
                    }
                    else if((HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1) ||
                            (HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1))
                    {
                        ulRamp -= 111;
                    }
                    else
                    {
                        ulRamp--;
                    }
                    if(ulRamp & 0x80000000)
                    {
                        ulRamp = 0;
                    }

                    //
                    // Send the updated voltage ramp rate.
                    //
                    CANVCompInRampSet((ulRamp * 256) / 100);
                }
            }

            //
            // See if the compensation rate is being changed.
            //
            else if(ulPos == 4)
            {
                //
                // Only change the compensation rate if it is not already zero.
                //
                if(ulComp > 0)
                {
                    //
                    // Decrement the compensation rate.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1)
                    {
                        ulComp -= 11;
                    }
                    else if((HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1) ||
                            (HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1))
                    {
                        ulComp -= 111;
                    }
                    else
                    {
                        ulComp--;
                    }
                    if(ulComp & 0x80000000)
                    {
                        ulComp = 0;
                    }

                    //
                    // Send the updated compensation rate.
                    //
                    CANVCompCompRampSet((ulComp * 256) / 100);
                }
            }

            //
            // Clear the press flag for the left button.
            //
            HWREGBITW(&g_ulFlags, FLAG_LEFT_PRESSED) = 0;
            HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) = 0;
            HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) = 0;
            HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) = 0;
        }

        //
        // See if the right button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_PRESSED) == 1)
        {
            //
            // See if the device ID is being changed.
            //
            if(ulPos == 1)
            {
                //
                // Only change the device ID if it is less than 63.
                //
                if(g_ulCurrentID < 63)
                {
                    //
                    // Exit demo mode.
                    //
                    ulDemo = 0;
                    CanvasTextColorSet(g_psVCompWidgets + 2, ClrWhite);

                    //
                    // Set the voltage to 0 for the current device ID.
                    //
                    CANVCompSet(0, 0);

                    //
                    // Increment the device ID.
                    //
                    if((HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1))
                    {
                        if(g_ulCurrentID < 60)
                        {
                            CANSetID(g_ulCurrentID + 3);
                        }
                        else
                        {
                            CANSetID(63);
                        }
                    }
                    else
                    {
                        CANSetID(g_ulCurrentID + 1);
                    }

                    //
                    // Enable voltage compensation control mode.
                    //
                    CANVCompModeEnable();

                    //
                    // Set the voltage for the new device.
                    //
                    lVoltage = 0;
                    CANVCompSet(0, 0);

                    //
                    // Read the ramp rate.
                    //
                    if(CANReadParameter(LM_API_VCOMP_IN_RAMP, 0, &ulRamp,
                                        0) == 0)
                    {
                        ulRamp = 0;
                    }
                    else
                    {
                        ulRamp = (((ulRamp & 0xffff) * 100) + 128) / 256;
                    }

                    //
                    // Read the compensation rate.
                    //
                    if(CANReadParameter(LM_API_VCOMP_COMP_RAMP, 0, &ulComp,
                                        0) == 0)
                    {
                        ulComp = 0;
                    }
                    else
                    {
                        ulComp = (((ulComp & 0xffff) * 100) + 128) / 256;
                    }
                }
            }

            //
            // See if the voltage is being changed.
            //
            else if(ulPos == 2)
            {
                //
                // Only change the voltage if it is not already full forward.
                //
                if(lVoltage < 120)
                {
                    //
                    // Increment the voltage.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1)
                    {
                        lVoltage += 11;
                    }
                    else if((HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1) ||
                            (HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1))
                    {
                        lVoltage += 111;
                    }
                    else
                    {
                        lVoltage++;
                    }
                    if(lVoltage > 120)
                    {
                        lVoltage = 120;
                    }

                    //
                    // Send the updated voltage to the motor controller if a
                    // delayed update is not in progress.
                    //
                    if(ulDelay == 0)
                    {
                        CANVCompSet((lVoltage * 256) / 10, 0);
                    }
                }
            }

            //
            // See if the voltage ramp rate is being changed.
            //
            else if(ulPos == 3)
            {
                //
                // Only change the ramp rate if it is not already the maximum.
                //
                if(ulRamp < 1200)
                {
                    //
                    // Increment the voltage ramp rate.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1)
                    {
                        ulRamp += 11;
                    }
                    else if((HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1) ||
                            (HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1))
                    {
                        ulRamp += 111;
                    }
                    else
                    {
                        ulRamp++;
                    }
                    if(ulRamp > 1200)
                    {
                        ulRamp = 1200;
                    }

                    //
                    // Send the updated voltage ramp rate.
                    //
                    CANVCompInRampSet((ulRamp * 256) / 100);
                }
            }

            //
            // See if the compensation rate is being changed.
            //
            else if(ulPos == 4)
            {
                //
                // Only change the compensation rate if it is not already the
                // maximum.
                //
                if(ulComp < 1200)
                {
                    //
                    // Increment the compensation rate.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1)
                    {
                        ulComp += 11;
                    }
                    else if((HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1) ||
                            (HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1))
                    {
                        ulComp += 111;
                    }
                    else
                    {
                        ulComp++;
                    }
                    if(ulComp > 1200)
                    {
                        ulComp = 1200;
                    }

                    //
                    // Send the updated compensation rate.
                    //
                    CANVCompCompRampSet((ulComp * 256) / 100);
                }
            }

            //
            // Clear the press flag for the right button.
            //
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_PRESSED) = 0;
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) = 0;
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) = 0;
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) = 0;
        }

        //
        // See if the select button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_SELECT_PRESSED) == 1)
        {
            //
            // Clear the press flag for the select button.
            //
            HWREGBITW(&g_ulFlags, FLAG_SELECT_PRESSED) = 0;

            //
            // See if the cursor is on the top row of the screen.
            //
            if(ulPos == 0)
            {
                //
                // Display the menu.
                //
                ulIdx = DisplayMenu(PANEL_VCOMP);

                //
                // See if another panel was selected.
                //
                if(ulIdx != PANEL_VCOMP)
                {
                    //
                    // Disable the status display.
                    //
                    StatusDisable();

                    //
                    // Remove the "VComp Control Mode" panel widgets.
                    //
                    for(ulPos = 0; ulPos < NUM_WIDGETS; ulPos++)
                    {
                        WidgetRemove((tWidget *)(g_psVCompWidgets + ulPos));
                    }
                    CanvasTextColorSet(g_psVCompWidgets + 2, ClrWhite);

                    //
                    // Set the output voltage to zero.
                    //
                    CANVCompSet(0, 0);

                    //
                    // Return the ID of the newly selected panel.
                    //
                    return(ulIdx);
                }

                //
                // Since the "VComp Control Mode" panel was selected from the
                // menu, move the cursor down one row.
                //
                CanvasFillOff(g_psVCompWidgets);
                ulPos++;
                CanvasFillOn(g_psVCompWidgets + 1);
            }

            //
            // See if the cursor is on the ID selection.
            //
            else if(ulPos == 1)
            {
                //
                // Toggle demo mode.
                //
                ulDemo ^= 1;

                //
                // See if the demo has just been disabled.
                //
                if(ulDemo == 0)
                {
                    //
                    // Set the output voltage to zero.
                    //
                    lVoltage = 0;
                    CANVCompSet(0, 0);

                    //
                    // Indicate that demo mode has exited by setting the text
                    // color to white.
                    //
                    CanvasTextColorSet(g_psVCompWidgets + 2, ClrWhite);
                }

                //
                // Otherwise start demo mode.
                //
                else
                {
                    //
                    // Indicate that demo mode is active by setting the text
                    // color to gray.
                    //
                    CanvasTextColorSet(g_psVCompWidgets + 2, ClrSelected);

                    //
                    // Start with the first step.
                    //
                    ulStep = 0;

                    //
                    // Set the voltage as directed by the first step.
                    //
                    lVoltage = g_plVCompDemo[0][0];
                    CANVCompSet((lVoltage * 256) / 10, 0);

                    //
                    // Set the time delay for the first step.
                    //
                    ulTime = g_ulTickCount + g_plVCompDemo[0][1];
                }
            }

            //
            // See if the cursor is on the voltage selection.
            //
            else if(ulPos == 2)
            {
                //
                // Toggle the state of the delayed update.
                //
                ulDelay ^= 1;

                //
                // See if a delayed update should be performed.
                //
                if(ulDelay == 0)
                {
                    //
                    // Send the delayed voltage update.
                    //
                    CANVCompSet((lVoltage * 256) / 10, 0);

                    //
                    // Change the text color of the voltage selection to white
                    // to indicate that updates will occur immediately.
                    //
                    CanvasTextColorSet(g_psVCompWidgets + 2, ClrWhite);
                }
                else
                {
                    //
                    // Change the text color of the voltage selection to black
                    // to indicate that updates will be delayed.
                    //
                    CanvasTextColorSet(g_psVCompWidgets + 2, ClrBlack);
                }
            }
        }
    }
}
Esempio n. 15
0
void
NNCommand2(Connection *conn)
{
    char *ptr;
    char *cmd;
    char *buf;
    Command *scan;
    int len;

    conn->co_Func = NNCommand2;
    conn->co_State = "waitcmd";

    /*
     * we have to be careful in regards to recursive operation, nor do
     * we want one descriptor to hog the process.  We can't set RFds
     * because the next command may already be entirely loaded into an
     * MBuf so setting RFds may not unblock us.  Instead, we set WFds
     * which basically forces a wakeup at some point in the future.
     */

    if (conn->co_FCounter) {
	FD_SET(conn->co_Desc->d_Fd, &WFds);
	/*
	 * if the other side closed the connection, select() is
	 * not going to wake up for write(!) so set RFds too.
	 */
	if (conn->co_TMBuf.mh_WError)
	    FD_SET(conn->co_Desc->d_Fd, &RFds);
	return;
    }
    ++conn->co_FCounter;

    /*
     * if there is still output pending, do not process the next
     * command.
     */
    if (conn->co_TMBuf.mh_Bytes > 0 && !conn->co_TMBuf.mh_WError)
	return;

    /*
     * get command
     */

    if ((len = MBReadLine(&conn->co_RMBuf, &buf)) == 0) {
	StatusUpdate(conn, "(idle)");
	return;
    }

    conn->co_ByteCountType = DRBC_NONE;

    /*
     * check EOF
     */

    if (len < 0 || conn->co_TMBuf.mh_WError) {
	NNTerminate(conn);
	return;
    }

    /*
     * strip CR LF
     */

    ptr = buf;

    if (len > 1 && ptr[len-2] == '\r')
	ptr[len-2] = 0;

    if (DebugOpt)
	printf("command: %s\n", ptr);

    if (strncasecmp(ptr, "authinfo pass ", 14)) {
        LogCmd(conn, '<', ptr);
    } else {
        LogCmd(conn, '<', "authinfo pass **unlogged**");
    }

    if (conn->co_Auth.dr_Flags & DF_USEPROXIED) {
      struct sockaddr_in sin;
      char *pt = NULL;

      if (strncasecmp(ptr, "proxied ", 8) || ! ((pt = strrchr(ptr, ':')))) {
          MBLogPrintf(conn,
              &conn->co_TMBuf,
              "400 %s: Proxy authentication failure.\r\n",
              conn->co_Auth.dr_VServerDef->vs_HostName
          );
          NNTerminate(conn);
      }

      *pt++ = '\0';
      ptr += 8;

      bzero((void *)&sin, sizeof(&sin));
      sin.sin_family = AF_INET;
      sin.sin_port = htons(atoi(pt));
      sin.sin_addr.s_addr = inet_addr(ptr);
      bcopy(&sin, &conn->co_Auth.dr_Addr, sizeof(conn->co_Auth.dr_Addr));

      conn->co_Auth.dr_Flags &= ~DF_USEPROXIED;
      conn->co_Auth.dr_ResultFlags = DR_REQUIRE_DNS;
      return;
    }

    /*
     * extract command (note: StatusUpdate() will limit the line length)
     */

    StatusUpdate(conn, "%s", ptr);

    if ((cmd = parseword(&ptr, " \t")) == NULL) {
	NNCommand(conn);
	return;
    }
    {
	int i;

	for (i = 0; cmd[i]; ++i)
	    cmd[i] = tolower((int)(unsigned char)cmd[i]);
    }

    /*
     * Locate and execute command
     */

    for (scan = &Cmds[0]; scan < &Cmds[arysize(Cmds)]; ++scan) {
	if (strcmp(cmd, scan->cmd_Name) == 0) {
	    if (conn->co_Flags & COF_SERVER) {
		if (scan->cmd_Flags & CMDF_SERVER) {
		    if ((conn->co_Auth.dr_Flags & DF_FEEDONLY) == 0)
			break;
		    if ((scan->cmd_Flags & CMDF_NOTFEEDONLY) == 0)
			break;
		}
	    } else {
		if (scan->cmd_Flags & CMDF_READER)
		    break;
	    }
	}
    }
    if (scan < &Cmds[arysize(Cmds)]) {
	if ((scan->cmd_Flags & CMDF_AUTH) &&
	    (conn->co_Auth.dr_Flags & DF_AUTHREQUIRED)
	) {
	    MBLogPrintf(conn, &conn->co_TMBuf, "480 Authentication required for command\r\n");
	    NNCommand(conn);
	} else {
	    conn->co_ByteCountType = scan->cmd_DRBC_Type;
	    scan->cmd_Func(conn, &ptr);
	}
    } else {
	NNUnknownCommand(conn);
    }
}
void ItemsManagerWorker::OnTabReceived(int request_id) {
    if (!replies_.count(request_id)) {
        QLOG_WARN() << "Received a reply for request" << request_id << "that was not requested.";
        return;
    }

    ItemsReply reply = replies_[request_id];
    QLOG_INFO() << "Received a reply for" << reply.request.location.GetHeader().c_str();
    QByteArray bytes = reply.network_reply->readAll();
    rapidjson::Document doc;
    doc.Parse(bytes.constData());

    bool error = false;
    if (!doc.IsObject()) {
        QLOG_WARN() << request_id << "got a non-object response";
        error = true;
    } else if (doc.HasMember("error")) {
        // this can happen if user is browsing stash in background and we can't know about it
        QLOG_WARN() << request_id << "got 'error' instead of stash tab contents";
        error = true;
    }

    // re-queue a failed request
    if (error)
        QueueRequest(reply.request.network_request, reply.request.location);

    ++requests_completed_;

    if (!error)
        ++total_completed_;

    bool throttled = false;
    if (requests_completed_ == requests_needed_ && queue_.size() > 0) {
        throttled = true;
        QLOG_INFO() << "Sleeping one minute to prevent throttling.";
        QTimer::singleShot(kThrottleSleep * 1000, this, SLOT(FetchItems()));
    }
    CurrentStatusUpdate status = CurrentStatusUpdate();
    status.state = throttled ? ProgramState::ItemsPaused : ProgramState::ItemsReceive;
    status.progress = total_completed_;
    status.total = total_needed_;
    if (total_completed_ == total_needed_)
        status.state = ProgramState::ItemsCompleted;
    emit StatusUpdate(status);

    if (error)
        return;

    ParseItems(&doc["items"], reply.request.location, doc.GetAllocator());

    if (total_completed_ == total_needed_) {
        // all requests completed
        emit ItemsRefreshed(items_, tabs_, false);

        // since we build items_as_string_ in a hackish way inside ParseItems last character will either be
        // ' ' when no items were parsed or ',' when at least one item is parsed, and the first character is '['
        items_as_string_[items_as_string_.size() - 1] = ']';

        // DataManager is thread safe so it's ok to call it here
        data_manager_.Set("items", items_as_string_);
        data_manager_.Set("tabs", tabs_as_string_);

        updating_ = false;
        QLOG_INFO() << "Finished updating stash.";

        // if we're at the verge of getting throttled, sleep so we don't
        if (requests_completed_ == kThrottleRequests)
            QTimer::singleShot(kThrottleSleep, this, SLOT(PreserveSelectedCharacter()));
        else
            PreserveSelectedCharacter();
    }

    reply.network_reply->deleteLater();
}
Esempio n. 17
0
void
HandleReaderMsg(ForkDesc *desc)
{
    int r;
    int recv_fd;
    DnsRes  dres;

    if ((r = RecvMsg(desc->d_Fd, &recv_fd, &dres)) == sizeof(DnsRes)) {
	if (recv_fd >= MAXFDS) {
	    logit(LOG_WARNING, "fd too large %d/%d, increase MAXFDS for select. Closing fd", recv_fd, MAXFDS);
	    /*
	     * Tell the main server that we are done with the connection
	     */
	    fcntl(TFd, F_SETFL, 0);
	    SendMsg(TFd, recv_fd, &dres);
	    fcntl(TFd, F_SETFL, O_NONBLOCK);
	} else if (recv_fd >= 0) {
	    ForkDesc *ndesc;
	    Connection *conn;
	    char vsbuf[11];
	    char hsbuf[31];

	    if (ReadAccessCache() == 1) {
		ScanThreads(THREAD_NNTP, UpdateAuthDetails);
		ScanThreads(THREAD_SPOOL, UpdateAuthDetails);
		ScanThreads(THREAD_READER, UpdateAuthDetails);
		ScanThreads(THREAD_SPOOL, UpdateAuthDetails);
		ScanThreads(THREAD_FEEDER, UpdateAuthDetails);
		ClearOldAccessMap();
	    }
	    SetAuthDetails(&dres, dres.dr_ReaderName);

	    ndesc = AddThread("client", recv_fd, -1, THREAD_NNTP, makeReaderSlot(), 0);
	    ++NumReaders;
	    if (DebugOpt)
		printf("add thread fd=%d\n", recv_fd);

	    FD_SET(ndesc->d_Fd, &WFds);	/* will cause immediate effect */
	    conn = InitConnection(ndesc, &dres);
	    if (conn->co_Auth.dr_Flags & DF_FEED)
		conn->co_Flags |= COF_SERVER;

	    snprintf(vsbuf, sizeof(vsbuf), "%s", conn->co_Auth.dr_VServerDef->vs_Name);

	    snprintf(hsbuf, sizeof(hsbuf), "%s%s%s%s%s",
		*conn->co_Auth.dr_AuthUser ? conn->co_Auth.dr_AuthUser : "",
		*conn->co_Auth.dr_AuthUser ? "/" : "",
		*conn->co_Auth.dr_IdentUser ? conn->co_Auth.dr_IdentUser : "",
		*conn->co_Auth.dr_IdentUser ? "@" : "",
		conn->co_Auth.dr_Host);
	    RTStatusBase(conn->co_Desc->d_Slot, "ACTV %-10s %-30s", vsbuf, hsbuf);

	    StatusUpdate(conn, "(startup)");
	    if (conn->co_Auth.dr_ResultFlags & DR_REQUIRE_DNS)
		NNAuthDone(conn);
	    else
		NNWriteHello(conn);
	} else {
	    if (DebugOpt)
		printf("recvmsg(): EOF1\n");
	    DelThread(desc);
	    TerminatePending = 1;
	}
    }

    /*
     * If recv error, check errno.  If temporary error,
     * leave r negative (select loop).  Set r = 0 to 
     * terminate.
     */

    if (r != sizeof(DnsRes) && r != -1) {
	if (DebugOpt)
	    printf("recvmsg(): Bad size read from RecvMsg\n");
    }
    if (r < 0) {
	if (errno != EINTR &&
	    errno != EWOULDBLOCK &&
	    errno != EAGAIN
	) {
	    r = 0;
	}
    }

    /*
     * EOF (or error)
     */

    if (r == 0) {
	if (DebugOpt)
	    printf("recvmsg(): EOF/error from parent %s\n", strerror(errno));
	DelThread(desc);
	TerminatePending = 1;
    }
}
Esempio n. 18
0
//*****************************************************************************
//
// Displays the "Position Control Mode" panel.  The returned valud is the ID of
// the panel to be displayed instead of the "Position Control Mode" panel.
//
//*****************************************************************************
unsigned long
DisplayPosition(void)
{
    unsigned long ulPos, ulIdx, ulDelay, ulDemo, ulTime, ulStep;

    //
    // Read the current position mode configuration.
    //
    PositionConfigRead();

    //
    // Enable position control mode.
    //
    CANPositionModeEnable(((g_sPositionConfig.lPosition / 100) * 65536) +
                          (((g_sPositionConfig.lPosition % 100) * 65536) /
                           100));

    //
    // Initially, updates to the position occur immediately.
    //
    ulDelay = 0;

    //
    // Initially, demo mode is disabled.
    //
    ulDemo = 0;
    ulTime = 0;
    ulStep = 0;

    //
    // Disable the widget fill for all the widgets except the one for the
    // device ID selection.
    //
    for(ulIdx = 0; ulIdx < 7; ulIdx++)
    {
        CanvasFillOff(g_psPositionWidgets + ulIdx);
    }
    CanvasFillOn(g_psPositionWidgets + 1);

    //
    // Add the "Position Control Mode" panel widgets to the widget list.
    //
    for(ulIdx = 0; ulIdx < NUM_WIDGETS; ulIdx++)
    {
        WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPositionWidgets + ulIdx));
    }

    //
    // Enable the status display.
    //
    StatusEnable(0);

    //
    // Set the default cursor position to the device ID selection.
    //
    ulPos = 1;

    //
    // Loop forever.  This loop will be explicitly exited when the proper
    // condition is detected.
    //
    while(1)
    {
        //
        // Print out the current device ID.
        //
        usnprintf(g_pcIDBuffer, sizeof(g_pcIDBuffer), "%d", g_ulCurrentID);

        //
        // Print out the current position.
        //
        if(g_sPositionConfig.lPosition < 0)
        {
            usnprintf(g_pcPositionBuffer, sizeof(g_pcPositionBuffer),
                      "-%d.%02d", (0 - g_sPositionConfig.lPosition) / 100,
                      (0 - g_sPositionConfig.lPosition) % 100);
        }
        else
        {
            usnprintf(g_pcPositionBuffer, sizeof(g_pcPositionBuffer),
                      "%d.%02d", g_sPositionConfig.lPosition / 100,
                      g_sPositionConfig.lPosition % 100);
        }

        //
        // Print out the current P coefficient.
        //
        if(g_sPositionConfig.lP < 0)
        {
            usnprintf(g_pcPositionPBuffer, sizeof(g_pcPositionPBuffer),
                      "-%d.%03d", (0 - g_sPositionConfig.lP) / 1000,
                      (0 - g_sPositionConfig.lP) % 1000);
        }
        else
        {
            usnprintf(g_pcPositionPBuffer, sizeof(g_pcPositionPBuffer),
                      "%d.%03d", g_sPositionConfig.lP / 1000,
                      g_sPositionConfig.lP % 1000);
        }

        //
        // Irint out the current I coefficient.
        //
        if(g_sPositionConfig.lI < 0)
        {
            usnprintf(g_pcPositionIBuffer, sizeof(g_pcPositionIBuffer),
                      "-%d.%03d", (0 - g_sPositionConfig.lI) / 1000,
                      (0 - g_sPositionConfig.lI) % 1000);
        }
        else
        {
            usnprintf(g_pcPositionIBuffer, sizeof(g_pcPositionIBuffer),
                      "%d.%03d", g_sPositionConfig.lI / 1000,
                      g_sPositionConfig.lI % 1000);
        }

        //
        // Print out the current D coefficient.
        //
        if(g_sPositionConfig.lD < 0)
        {
            usnprintf(g_pcPositionDBuffer, sizeof(g_pcPositionDBuffer),
                      "-%d.%03d", (0 - g_sPositionConfig.lD) / 1000,
                      (0 - g_sPositionConfig.lD) % 1000);
        }
        else
        {
            usnprintf(g_pcPositionDBuffer, sizeof(g_pcPositionDBuffer),
                      "%d.%03d", g_sPositionConfig.lD / 1000,
                      g_sPositionConfig.lD % 1000);
        }

        //
        // Print out the current position reference source.
        //
        usnprintf(g_pcReferenceBuffer, sizeof(g_pcReferenceBuffer), "%s",
                  g_ppcPosReference[g_sPositionConfig.ulPosRef]);

        //
        // Update the status display.
        //
        StatusUpdate();

        //
        // Update the display.
        //
        DisplayFlush();

        //
        // See if a serial download has begun.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_SERIAL_BOOTLOADER) == 1)
        {
            //
            // Disable the status display.
            //
            StatusDisable();

            //
            // Remove the "Position Control Mode" panel widgets.
            //
            for(ulIdx = 0; ulIdx < NUM_WIDGETS; ulIdx++)
            {
                WidgetRemove((tWidget *)(g_psPositionWidgets + ulIdx));
            }
            CanvasTextColorSet(g_psPositionWidgets + 2, ClrWhite);

            //
            // Disable position control mode.
            //
            CANPositionModeDisable();

            //
            // Return the ID of the update panel.
            //
            return(PANEL_UPDATE);
        }

        //
        // See if demo mode is enabled.
        //
        if(ulDemo != 0)
        {
            //
            // See if the current time delay has expired.
            //
            if(ulTime < g_ulTickCount)
            {
                //
                // Increment to the next step, wrapping back to the beginning
                // of the sequence when the end has been reached.
                //
                ulStep++;
                if(ulStep == (sizeof(g_plPositionDemo) /
                              sizeof(g_plPositionDemo[0])))
                {
                    ulStep = 0;
                }

                //
                // Set the position as directed by the next step.
                //
                g_sPositionConfig.lPosition = g_plPositionDemo[ulStep][0];
                CANPositionSet(((g_sPositionConfig.lPosition / 100) * 65536) +
                               (((g_sPositionConfig.lPosition % 100) * 65536) /
                                100), 0);

                //
                // Set the time delay for this step.
                //
                ulTime = g_ulTickCount + g_plPositionDemo[ulStep][1];
            }
        }

        //
        // See if the up button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_UP_PRESSED) == 1)
        {
            //
            // Only move the cursor if it is not already at the top of the
            // screen and a delayed position update is not in progress.
            //
            if((ulPos != 0) && (ulDelay == 0))
            {
                //
                // Disable the widget fill for the currently selected widget.
                //
                CanvasFillOff(g_psPositionWidgets + ulPos);

                //
                // Decrement the cursor row, skipping the position row when
                // demo mode is enabled.
                //
                ulPos--;
                if((ulPos == 2) && (ulDemo != 0))
                {
                    ulPos--;
                }

                //
                // Enable the widget fill for the newly selected widget.
                //
                CanvasFillOn(g_psPositionWidgets + ulPos);
            }

            //
            // Clear the press flag for the up button.
            //
            HWREGBITW(&g_ulFlags, FLAG_UP_PRESSED) = 0;
        }

        //
        // See if the down button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_DOWN_PRESSED) == 1)
        {
            //
            // Only move the cursor if it is not already at the bottom of the
            // screen and a delayed position update is not in progress.
            //
            if((ulPos != 6) && (ulDelay == 0))
            {
                //
                // Disable the widget fill for the currently selected widget.
                //
                CanvasFillOff(g_psPositionWidgets + ulPos);

                //
                // Increment the cursor row, skipping the position row when
                // demo mode is enabled.
                //
                ulPos++;
                if((ulPos == 2) && (ulDemo != 0))
                {
                    ulPos++;
                }

                //
                // Enable the widget fill for the newly selected widget.
                //
                CanvasFillOn(g_psPositionWidgets + ulPos);
            }

            //
            // Clear the press flag for the down button.
            //
            HWREGBITW(&g_ulFlags, FLAG_DOWN_PRESSED) = 0;
        }

        //
        // See if the left button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_LEFT_PRESSED) == 1)
        {
            //
            // See if the device ID is being changed.
            //
            if(ulPos == 1)
            {
                //
                // Only change the device ID if it is greater than one.
                //
                if(g_ulCurrentID > 1)
                {
                    //
                    // Exit demo mode.
                    //
                    ulDemo = 0;
                    CanvasTextColorSet(g_psPositionWidgets + 2, ClrWhite);

                    //
                    // Disable position control mode for the current device ID.
                    //
                    CANPositionModeDisable();

                    //
                    // Decrement the device ID.
                    //
                    if((HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1))
                    {
                        if(g_ulCurrentID > 3)
                        {
                            CANSetID(g_ulCurrentID - 3);
                        }
                        else
                        {
                            CANSetID(1);
                        }
                    }
                    else
                    {
                        CANSetID(g_ulCurrentID - 1);
                    }

                    //
                    // Read the configuration of the new device.
                    //
                    PositionConfigRead();

                    //
                    // Enable position control mode.
                    //
                    CANPositionModeEnable(((g_sPositionConfig.lPosition /
                                            100) * 65536) +
                                          (((g_sPositionConfig.lPosition %
                                             100) * 65536) / 100));
                }
            }

            //
            // See if the position is being changed.
            //
            else if(ulPos == 2)
            {
                //
                // Only change the position if it is not already fully
                // negative.
                //
                if(g_sPositionConfig.lPosition > -20000)
                {
                    //
                    // Decrement the position.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lPosition -= 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lPosition -= 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lPosition -= 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lPosition--;
                    }
                    if(g_sPositionConfig.lPosition < -20000)
                    {
                        g_sPositionConfig.lPosition = -20000;
                    }

                    //
                    // Send the updated position to the motor controller if a
                    // delayed update is not in progress.
                    //
                    if(ulDelay == 0)
                    {
                        CANPositionSet(((g_sPositionConfig.lPosition / 100) *
                                        65536) +
                                       (((g_sPositionConfig.lPosition % 100) *
                                         65536) / 100), 0);
                    }
                }
            }

            //
            // See if the position P gain is being changed.
            //
            else if(ulPos == 3)
            {
                //
                // Only change the P gain if it is not already fully negative.
                //
                if(g_sPositionConfig.lP > (-32767 * 1000))
                {
                    //
                    // Decrement the P gain.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lP -= 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lP -= 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lP -= 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lP--;
                    }
                    if(g_sPositionConfig.lP < (-32767 * 1000))
                    {
                        g_sPositionConfig.lP = -32767 * 1000;
                    }

                    //
                    // Send the new P gain to the motor controller.
                    //
                    CANPositionPGainSet(((g_sPositionConfig.lP / 1000) *
                                         65536) +
                                        (((g_sPositionConfig.lP % 1000) *
                                          65536) / 1000));
                }
            }

            //
            // See if the position I gain is being changed.
            //
            else if(ulPos == 4)
            {
                //
                // Only change the I gain if it is not already fully negative.
                //
                if(g_sPositionConfig.lI > (-32767 * 1000))
                {
                    //
                    // Decrement the I gain.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lI -= 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lI -= 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lI -= 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lI--;
                    }
                    if(g_sPositionConfig.lI < (-32767 * 1000))
                    {
                        g_sPositionConfig.lI = -32767 * 1000;
                    }

                    //
                    // Send the new I gain to the motor controller.
                    //
                    CANPositionIGainSet(((g_sPositionConfig.lI / 1000) *
                                         65536) +
                                        (((g_sPositionConfig.lI % 1000) *
                                          65536) / 1000));
                }
            }

            //
            // See if the position D gain is being changed.
            //
            else if(ulPos == 5)
            {
                //
                // Only change the D gain if it is not already fully negative.
                //
                if(g_sPositionConfig.lD > (-32767 * 1000))
                {
                    //
                    // Decrement the D gain.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lD -= 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lD -= 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lD -= 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lD--;
                    }
                    if(g_sPositionConfig.lD < (-32767 * 1000))
                    {
                        g_sPositionConfig.lD = -32767 * 1000;
                    }

                    //
                    // Send the new D gain to the motor controller.
                    //
                    CANPositionDGainSet(((g_sPositionConfig.lD / 1000) *
                                         65536) +
                                        (((g_sPositionConfig.lD % 1000) *
                                          65536) / 1000));
                }
            }

            //
            // See if the position reference source is being changed.
            //
            else if(ulPos == 6)
            {
                //
                // Toggle to the other position reference source.
                //
                g_sPositionConfig.ulPosRef ^= 1;

                //
                // Send the position reference source to the motor controller.
                //
                CANPositionRefSet(g_sPositionConfig.ulPosRef);
            }

            //
            // Clear the press flag for the left button.
            //
            HWREGBITW(&g_ulFlags, FLAG_LEFT_PRESSED) = 0;
            HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL1) = 0;
            HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL2) = 0;
            HWREGBITW(&g_ulFlags, FLAG_LEFT_ACCEL3) = 0;
        }

        //
        // See if the right button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_PRESSED) == 1)
        {
            //
            // See if the device ID is being changed.
            //
            if(ulPos == 1)
            {
                //
                // Only change the device ID if it is less than 63.
                //
                if(g_ulCurrentID < 63)
                {
                    //
                    // Exit demo mode.
                    //
                    ulDemo = 0;
                    CanvasTextColorSet(g_psPositionWidgets + 2, ClrWhite);

                    //
                    // Disable position control mode for the current device ID.
                    //
                    CANPositionModeDisable();

                    //
                    // Increment the device ID.
                    //
                    if((HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1) ||
                       (HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1))
                    {
                        if(g_ulCurrentID < 60)
                        {
                            CANSetID(g_ulCurrentID + 3);
                        }
                        else
                        {
                            CANSetID(63);
                        }
                    }
                    else
                    {
                        CANSetID(g_ulCurrentID + 1);
                    }

                    //
                    // Read the configuration of the new device.
                    //
                    PositionConfigRead();

                    //
                    // Enable position control mode.
                    //
                    CANPositionModeEnable(((g_sPositionConfig.lPosition /
                                            100) * 65536) +
                                          (((g_sPositionConfig.lPosition %
                                             100) * 65536) / 100));
                }
            }

            //
            // See if the position is being changed.
            //
            else if(ulPos == 2)
            {
                //
                // Only change the position if it is not already fully
                // positive.
                //
                if(g_sPositionConfig.lPosition < 20000)
                {
                    //
                    // Increment the position.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lPosition += 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lPosition += 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lPosition += 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lPosition++;
                    }
                    if(g_sPositionConfig.lPosition > 20000)
                    {
                        g_sPositionConfig.lPosition = 20000;
                    }

                    //
                    // Send the updated position to the motor controller if a
                    // delayed update is not in progress.
                    //
                    if(ulDelay == 0)
                    {
                        CANPositionSet(((g_sPositionConfig.lPosition / 100) *
                                        65536) +
                                       (((g_sPositionConfig.lPosition % 100) *
                                         65536) / 100), 0);
                    }
                }
            }

            //
            // See if the position P gain is being changed.
            //
            else if(ulPos == 3)
            {
                //
                // Only change the P gain if it is not already fully positive.
                //
                if(g_sPositionConfig.lP < (32767 * 1000))
                {
                    //
                    // Increment the P gain.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lP += 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lP += 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lP += 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lP++;
                    }
                    if(g_sPositionConfig.lP > (32767 * 1000))
                    {
                        g_sPositionConfig.lP = 32767 * 1000;
                    }

                    //
                    // Send the new P gain to the motor controller.
                    //
                    CANPositionPGainSet(((g_sPositionConfig.lP / 1000) *
                                         65536) +
                                        (((g_sPositionConfig.lP % 1000) *
                                          65536) / 1000));
                }
            }

            //
            // See if the position I gain is being changed.
            //
            else if(ulPos == 4)
            {
                //
                // Only change the I gain if it is not already fully positive.
                //
                if(g_sPositionConfig.lI < (32767 * 1000))
                {
                    //
                    // Increment the I gain.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lI += 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lI += 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lI += 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lI++;
                    }
                    if(g_sPositionConfig.lI > (32767 * 1000))
                    {
                        g_sPositionConfig.lI = 32767 * 1000;
                    }

                    //
                    // Send the new I gain to the motor controller.
                    //
                    CANPositionIGainSet(((g_sPositionConfig.lI / 1000) *
                                         65536) +
                                        (((g_sPositionConfig.lI % 1000) *
                                          65536) / 1000));
                }
            }

            //
            // See if the position D gain is being changed.
            //
            else if(ulPos == 5)
            {
                //
                // Only change the D gain if it is not already fully positive.
                //
                if(g_sPositionConfig.lD < (32767 * 1000))
                {
                    //
                    // Increment the D gain.
                    //
                    if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) == 1)
                    {
                        g_sPositionConfig.lD += 11;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) == 1)
                    {
                        g_sPositionConfig.lD += 111;
                    }
                    else if(HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) == 1)
                    {
                        g_sPositionConfig.lD += 1111;
                    }
                    else
                    {
                        g_sPositionConfig.lD++;
                    }
                    if(g_sPositionConfig.lD > (32767 * 1000))
                    {
                        g_sPositionConfig.lD = 32767 * 1000;
                    }

                    //
                    // Send the new D gain to the motor controller.
                    //
                    CANPositionDGainSet(((g_sPositionConfig.lD / 1000) *
                                         65536) +
                                        (((g_sPositionConfig.lD % 1000) *
                                          65536) / 1000));
                }
            }

            //
            // See if the position reference source is being changed.
            //
            else if(ulPos == 6)
            {
                //
                // Toggle to the other position reference source.
                //
                g_sPositionConfig.ulPosRef ^= 1;

                //
                // Send the position reference source to the motor controller.
                //
                CANPositionRefSet(g_sPositionConfig.ulPosRef);
            }

            //
            // Clear the press flag for the right button.
            //
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_PRESSED) = 0;
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL1) = 0;
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL2) = 0;
            HWREGBITW(&g_ulFlags, FLAG_RIGHT_ACCEL3) = 0;
        }

        //
        // See if the select button was pressed.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_SELECT_PRESSED) == 1)
        {
            //
            // Clear the press flag for the select button.
            //
            HWREGBITW(&g_ulFlags, FLAG_SELECT_PRESSED) = 0;

            //
            // See if the cursor is on the top row of the screen.
            //
            if(ulPos == 0)
            {
                //
                // Display the menu.
                //
                ulIdx = DisplayMenu(PANEL_POSITION);

                //
                // See if another panel was selected.
                //
                if(ulIdx != PANEL_POSITION)
                {
                    //
                    // Disable the status display.
                    //
                    StatusDisable();

                    //
                    // Remove the "Position Control Mode" panel widgets.
                    //
                    for(ulPos = 0; ulPos < NUM_WIDGETS; ulPos++)
                    {
                        WidgetRemove((tWidget *)(g_psPositionWidgets + ulPos));
                    }
                    CanvasTextColorSet(g_psPositionWidgets + 2, ClrWhite);

                    //
                    // Disable position control mode.
                    //
                    CANPositionModeDisable();

                    //
                    // Return the ID of the newly selected panel.
                    //
                    return(ulIdx);
                }

                //
                // Since the "Position Control Mode" panel was selected from
                // the menu, move the cursor down one row.
                //
                CanvasFillOff(g_psPositionWidgets);
                ulPos++;
                CanvasFillOn(g_psPositionWidgets + 1);
            }

            //
            // See if the cursor is on the ID selection.
            //
            else if(ulPos == 1)
            {
                //
                // Toggle demo mode.
                //
                ulDemo ^= 1;

                //
                // See if the demo has just been disabled.
                //
                if(ulDemo == 0)
                {
                    //
                    // Set the output position to the current position.
                    //
                    if(g_lStatusPosition < 0)
                    {
                        g_sPositionConfig.lPosition =
                            (((g_lStatusPosition / 65536) * 100) +
                             ((((g_lStatusPosition % 65536) * 100) - 32768) /
                              65536));
                    }
                    else
                    {
                        g_sPositionConfig.lPosition =
                            (((g_lStatusPosition / 65536) * 100) +
                             ((((g_lStatusPosition % 65536) * 100) + 32768) /
                              65536));
                    }
                    CANPositionSet(((g_sPositionConfig.lPosition / 100) *
                                    65536) +
                                   (((g_sPositionConfig.lPosition % 100) *
                                     65536) / 100), 0);

                    //
                    // Indicate that demo mode has exited by setting the text
                    // color to white.
                    //
                    CanvasTextColorSet(g_psPositionWidgets + 2, ClrWhite);
                }

                //
                // Otherwise start demo mode.
                //
                else
                {
                    //
                    // Indicate that demo mode is active by setting the text
                    // color to gray.
                    //
                    CanvasTextColorSet(g_psPositionWidgets + 2, ClrSelected);

                    //
                    // Start with the first step.
                    //
                    ulStep = 0;

                    //
                    // Set the position as directed by the first step.
                    //
                    g_sPositionConfig.lPosition = g_plPositionDemo[0][0];
                    CANPositionSet(((g_sPositionConfig.lPosition / 100) *
                                    65536) +
                                   (((g_sPositionConfig.lPosition % 100) *
                                     65536) / 100), 0);

                    //
                    // Set the time delay for the first step.
                    //
                    ulTime = g_ulTickCount + g_plPositionDemo[0][1];
                }
            }

            //
            // See if the cursor is on the position selection.
            //
            else if(ulPos == 2)
            {
                //
                // Toggle the state of the delayed update.
                //
                ulDelay ^= 1;

                //
                // See if a delayed update should be performed.
                //
                if(ulDelay == 0)
                {
                    //
                    // Send the delayed position update.
                    //
                    CANPositionSet(((g_sPositionConfig.lPosition / 100) *
                                    65536) +
                                   (((g_sPositionConfig.lPosition % 100) *
                                     65536) / 100), 0);

                    //
                    // Change the text color of the position selection to white
                    // to indicate that updates will occur immediately.
                    //
                    CanvasTextColorSet(g_psPositionWidgets + 2, ClrWhite);
                }
                else
                {
                    //
                    // Change the text color of the position selection to black
                    // to indicate that updates will be delayed.
                    //
                    CanvasTextColorSet(g_psPositionWidgets + 2, ClrBlack);
                }
            }
        }
    }
}
Esempio n. 19
0
void ItemsManager::OnStatusUpdate(const ItemsFetchStatus &status) {
    emit StatusUpdate(status);
}
Esempio n. 20
0
void ItemsManagerWorker::OnTabReceived(int request_id) {
    if (!replies_.count(request_id)) {
        QLOG_WARN() << "Received a reply for request" << request_id << "that was not requested.";
        return;
    }

    ItemsReply reply = replies_[request_id];

    bool cache_status = reply.network_reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool();

    if (cache_status) {
        QLOG_DEBUG() << "Received a cached reply for" << reply.request.location.GetHeader().c_str();
        ++cached_requests_completed_;
        ++total_cached_;
    } else {
        QLOG_DEBUG() << "Received a reply for" << reply.request.location.GetHeader().c_str();
    }

    QByteArray bytes = reply.network_reply->readAll();
    rapidjson::Document doc;
    doc.Parse(bytes.constData());

    bool error = false;
    if (!doc.IsObject()) {
        QLOG_WARN() << request_id << "got a non-object response";
        error = true;
    } else if (doc.HasMember("error")) {
        // this can happen if user is browsing stash in background and we can't know about it
        QLOG_WARN() << request_id << "got 'error' instead of stash tab contents";
        error = true;
    }

    // re-queue a failed request
    if (error) {
        // We can 'cache' error response document so make sure we remove it
        // before reque
        tab_cache_->remove(reply.request.network_request.url());
        QueueRequest(reply.request.network_request, reply.request.location);
    }

    ++requests_completed_;

    if (!error)
        ++total_completed_;

    bool throttled = false;
    if (requests_completed_ == requests_needed_ && queue_.size() > 0) {
        if (cached_requests_completed_ > 0) {
            // We basically don't want cached requests to count against throttle limit
            // so if we did get any cached requests fetch up to that number without a
            // large delay
            QTimer::singleShot(1, [&]() {
                FetchItems(cached_requests_completed_);
            });
        } else {
            throttled = true;
            QLOG_DEBUG() << "Sleeping one minute to prevent throttling.";
            QTimer::singleShot(kThrottleSleep * 1000, this, SLOT(FetchItems()));
        }
    }
    CurrentStatusUpdate status = CurrentStatusUpdate();
    status.state = throttled ? ProgramState::ItemsPaused : ProgramState::ItemsReceive;
    status.progress = total_completed_;
    status.total = total_needed_;
    status.cached = total_cached_;
    if (total_completed_ == total_needed_)
        status.state = ProgramState::ItemsCompleted;
    emit StatusUpdate(status);

    if (error)
        return;

    ParseItems(&doc["items"], reply.request.location, doc.GetAllocator());

    if (total_completed_ == total_needed_) {
        // It's possible that we receive character vs stash tabs out of order, or users
        // move items around in a tab and we get them in a different order. For
        // consistency we want to present the tab data in a deterministic way to the rest
        // of the application.  Especially so we don't try to update shop when nothing actually
        // changed.  So sort items_ here before emitting and then generate
        // item list as strings.

        std::sort(begin(items_), end(items_), [](const std::shared_ptr<Item> &a, const std::shared_ptr<Item> &b) {
            return b->location() < a->location();
        });

        QStringList tmp;
        for (auto const &item: items_) {
            tmp.push_back(item->json().c_str());
        }
        auto items_as_string = std::string("[") + tmp.join(",").toStdString() + "]";

        // all requests completed
        emit ItemsRefreshed(items_, tabs_, false);

        // DataStore is thread safe so it's ok to call it here
        data_.Set("items", items_as_string);
        data_.Set("tabs", tabs_as_string_);

        updating_ = false;
        QLOG_DEBUG() << "Finished updating stash.";

        // if we're at the verge of getting throttled, sleep so we don't
        if (requests_completed_ == kThrottleRequests)
            QTimer::singleShot(kThrottleSleep, this, SLOT(PreserveSelectedCharacter()));
        else
            PreserveSelectedCharacter();
    }

    reply.network_reply->deleteLater();
}
Esempio n. 21
0
void MainWindow::on_pushButton_3_clicked()
{
    StatusUpdate();
}