コード例 #1
0
ファイル: capture.cpp プロジェクト: monisha4/kstars-hackfest
void Capture::clearLog()
{
    logText.clear();
    emit newLog();
}
コード例 #2
0
ファイル: logbrowser.cpp プロジェクト: Absolight/mirall
LogBrowser::LogBrowser(QWidget *parent) :
    QDialog(parent),
    _logWidget( new LogWidget(parent) )
{
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    setObjectName("LogBrowser"); // for save/restoreGeometry()
    setWindowTitle(tr("Log Output"));
    setMinimumWidth(600);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    // mainLayout->setMargin(0);

    mainLayout->addWidget( _logWidget );

    QHBoxLayout *toolLayout = new QHBoxLayout;
    mainLayout->addLayout( toolLayout );

    // Search input field
    QLabel *lab = new QLabel(tr("&Search: "));
    _findTermEdit = new QLineEdit;
    lab->setBuddy( _findTermEdit );
    toolLayout->addWidget(lab);
    toolLayout->addWidget( _findTermEdit );

    // find button
    QPushButton *findBtn = new QPushButton;
    findBtn->setText( tr("&Find") );
    connect( findBtn, SIGNAL(clicked()), this, SLOT(slotFind()));
    toolLayout->addWidget( findBtn );

    // stretch
    toolLayout->addStretch(1);
    _statusLabel = new QLabel;
    toolLayout->addWidget( _statusLabel );
    toolLayout->addStretch(5);

    QDialogButtonBox *btnbox = new QDialogButtonBox;
    QPushButton *closeBtn = btnbox->addButton( QDialogButtonBox::Close );
    connect(closeBtn,SIGNAL(clicked()),this,SLOT(close()));

    mainLayout->addWidget( btnbox );

    // clear button
    _clearBtn = new QPushButton;
    _clearBtn->setText( tr("Clear") );
    _clearBtn->setToolTip( tr("Clear the log display.") );
    btnbox->addButton(_clearBtn, QDialogButtonBox::ActionRole);
    connect( _clearBtn, SIGNAL(clicked()), this, SLOT(slotClearLog()));

    // save Button
    _saveBtn = new QPushButton;
    _saveBtn->setText( tr("S&ave") );
    _saveBtn->setToolTip(tr("Save the log file to a file on disk for debugging."));
    btnbox->addButton(_saveBtn, QDialogButtonBox::ActionRole);
    connect( _saveBtn, SIGNAL(clicked()),this, SLOT(slotSave()));

    setLayout( mainLayout );

    setModal(false);

    // Direct connection for log comming from this thread, and queued for the one in a different thread
    connect(Logger::instance(), SIGNAL(newLog(QString)),this,SLOT(slotNewLog(QString)), Qt::AutoConnection);

    QAction *showLogWindow = new QAction(this);
    showLogWindow->setShortcut(QKeySequence("F12"));
    connect(showLogWindow, SIGNAL(triggered()), SLOT(close()));
    addAction(showLogWindow);

    MirallConfigFile cfg;
    cfg.restoreGeometry(this);
    int lines = cfg.maxLogLines();
    // qDebug() << "#        ##  Have " << lines << " Loglines!";
    _logWidget->document()->setMaximumBlockCount( lines );

}
コード例 #3
0
void Guide::clearLog()
{
    logText.clear();
    emit newLog();
}
コード例 #4
0
ファイル: phd2.cpp プロジェクト: Bugsbane/kstars
void PHD2::processPHD2Event(const QJsonObject &jsonEvent)
{
    QString eventName = jsonEvent["Event"].toString();

    if (events.contains(eventName) == false)
    {
        emit newLog(i18n("Unknown PHD2 event: %1", eventName));
        return;
    }

    event = events.value(eventName);

    switch (event)
    {
    case Version:
        emit newLog(i18n("PHD2: Version %1", jsonEvent["PHDVersion"].toString()));
        break;

    case CalibrationComplete:
        //state = CALIBRATION_SUCCESSFUL;
        // It goes immediately to guiding until PHD implements a calibration-only method
        state = GUIDING;
        emit newLog(i18n("PHD2: Calibration Complete."));
        emit calibrationCompleted(true);
        emit guideReady();
        break;

    case StartGuiding:
        state = GUIDING;
        if (connection != EQUIPMENT_CONNECTED)
        {
            connection = EQUIPMENT_CONNECTED;
            emit connected();
        }
        emit newLog(i18n("PHD2: Guiding Started."));
        emit autoGuidingToggled(true);
        break;

    case Paused:
        state = PAUSED;
        emit newLog(i18n("PHD2: Guiding Paused."));
        break;

    case StartCalibration:
        state = CALIBRATING;
        emit newLog(i18n("PHD2: Calibration Started."));
        break;

    case AppState:
        processPHD2State(jsonEvent["State"].toString());
        break;

    case CalibrationFailed:
        state = CALIBRATION_FAILED;
        emit newLog(i18n("PHD2: Calibration Failed (%1).", jsonEvent["Reason"].toString()));
        emit calibrationCompleted(false);
        break;

    case CalibrationDataFlipped:
        emit newLog(i18n("Calibration Data Flipped."));
        break;

    case LoopingExposures:
        //emit newLog(i18n("PHD2: Looping Exposures."));
        break;

    case LoopingExposuresStopped:
        emit newLog(i18n("PHD2: Looping Exposures Stopped."));
        break;

    case Settling:
        break;

    case SettleDone:
    {
        bool error=false;

        if (jsonEvent["Status"].toInt() != 0)
        {
            error = true;
            emit newLog(i18n("PHD2: Settling failed (%1).", jsonEvent["Error"].toString()));
        }

        if (state == GUIDING)
        {
            if (error)
                state = STOPPED;
        }
        else if (state == DITHERING)
        {
            if (error)
            {
                state = DITHER_FAILED;
                emit ditherFailed();
            }
            else
            {
                state = DITHER_SUCCESSFUL;
                emit ditherComplete();
            }
        }
    }
    break;

    case StarSelected:
        emit newLog(i18n("PHD2: Star Selected."));
        break;

    case StarLost:
        emit newLog(i18n("PHD2: Star Lost."));
        break;

    case GuidingStopped:
        emit newLog(i18n("PHD2: Guiding Stopped."));
        emit autoGuidingToggled(false);
        break;

    case Resumed:
        emit newLog(i18n("PHD2: Guiding Resumed."));
        state = GUIDING;
        break;

    case GuideStep:
    {
        double diff_ra_pixels, diff_de_pixels, diff_ra_arcsecs, diff_de_arcsecs;
        diff_ra_pixels = jsonEvent["RADistanceRaw"].toDouble();
        diff_de_pixels = jsonEvent["DecDistanceRaw"].toDouble();

        diff_ra_arcsecs = 206264.8062470963552 * diff_ra_pixels * ccd_pixel_width / focal;
        diff_de_arcsecs = 206264.8062470963552 * diff_de_pixels * ccd_pixel_height / focal;

        emit newAxisDelta(diff_ra_arcsecs, diff_de_arcsecs);
    }
        break;

    case GuidingDithered:
        emit newLog(i18n("PHD2: Guide Dithering."));
        break;

    case LockPositionSet:
        emit newLog(i18n("PHD2: Lock Position Set."));
        break;

    case LockPositionLost:
        emit newLog(i18n("PHD2: Lock Position Lost."));
        break;

    case Alert:
        emit newLog(i18n("PHD2 %1: %2", jsonEvent["Type"].toString(), jsonEvent["Msg"].toString()));
        break;

    }
}
コード例 #5
0
void Exchange_BitMarket::dataReceivedAuth(QByteArray data, int reqType)
{
    if(debugLevel)logThread->writeLog("RCV: "+data);
    if(data.size()&&data.at(0)==QLatin1Char('<'))return;

    bool success=true;
    QString errorString="";

	switch(reqType)
	{
	case 103: //ticker
        if(data.startsWith("{\"ask\":"))
        {
            QByteArray tickerHigh=getMidData("\"high\":",",\"",&data);
			if(!tickerHigh.isEmpty())
			{
                double newTickerHigh=tickerHigh.toDouble();
                if(newTickerHigh!=lastTickerHigh)
                    IndicatorEngine::setValue(baseValues.exchangeName,baseValues.currentPair.symbol,"High",newTickerHigh);
				lastTickerHigh=newTickerHigh;
			}

			QByteArray tickerLow=getMidData("\"low\":",",\"",&data);
			if(!tickerLow.isEmpty())
			{
                double newTickerLow=tickerLow.toDouble();
                if(newTickerLow!=lastTickerLow)
                    IndicatorEngine::setValue(baseValues.exchangeName,baseValues.currentPair.symbol,"Low",newTickerLow);
				lastTickerLow=newTickerLow;
			}

            QByteArray tickerSell=getMidData("\"bid\":",",\"",&data);
			if(!tickerSell.isEmpty())
			{
                double newTickerSell=tickerSell.toDouble();
                if(newTickerSell!=lastTickerSell)
                    IndicatorEngine::setValue(baseValues.exchangeName,baseValues.currentPair.symbol,"Sell",newTickerSell);
				lastTickerSell=newTickerSell;
			}

            QByteArray tickerBuy=getMidData("\"ask\":",",\"",&data);
			if(!tickerBuy.isEmpty())
			{
                double newTickerBuy=tickerBuy.toDouble();
                if(newTickerBuy!=lastTickerBuy)
                    IndicatorEngine::setValue(baseValues.exchangeName,baseValues.currentPair.symbol,"Buy",newTickerBuy);
				lastTickerBuy=newTickerBuy;
			}

            QByteArray tickerVolume=getMidData("\"volume\":","}",&data);
			if(!tickerVolume.isEmpty())
			{
                double newTickerVolume=tickerVolume.toDouble();
                if(newTickerVolume!=lastTickerVolume)
                    IndicatorEngine::setValue(baseValues.exchangeName,baseValues.currentPair.symbol,"Volume",newTickerVolume);
				lastTickerVolume=newTickerVolume;
			}

            QByteArray tickerLast=getMidData("\"last\":",",\"",&data);
            if(!tickerLast.isEmpty())
            {
                double newTickerLast=tickerLast.toDouble();
                if(newTickerLast!=lastTickerLast)
                    IndicatorEngine::setValue(baseValues.exchangeName,baseValues.currentPair.symbol,"Last",newTickerLast);
                lastTickerLast=newTickerLast;
            }

			if(isFirstTicker)
			{
				emit firstTicker();
				isFirstTicker=false;
			}
		}
        else {
            success=false;
            errorString+="Invalid ticker data. ";
        }
		break;//ticker
    case 109: //trades
        if(data.startsWith("[{\"amount\":"))
		{
			QStringList tradeList=QString(data).split("},{");
			QList<TradesItem> *newTradesItems=new QList<TradesItem>;

            quint32 currentTid=0;
			for(int n=tradeList.count()-1;n>=0;n--)
			{
				QByteArray tradeData=tradeList.at(n).toLatin1()+"}";
				TradesItem newItem;

                newItem.date=getMidData("\"date\":",",\"",&tradeData).toUInt();
                currentTid=getMidData("\"tid\":",",\"",&tradeData).toUInt();
                if(lastFetchTid<0&&newItem.date<-lastFetchTid)continue;
                if(currentTid<1000||lastFetchTid>=currentTid)continue;
                lastFetchTid=currentTid;
                newItem.price=getMidData("\"price\":",",\"",&tradeData).toDouble();
                newItem.amount=getMidData("\"amount\":",",\"",&tradeData).toDouble();
                newItem.orderType=getMidData("\"type\":\"","\"",&tradeData)=="ask"?1:-1;
                newItem.symbol=baseValues.currentPair.symbol;

				if(newItem.isValid())(*newTradesItems)<<newItem;
				else if(debugLevel)logThread->writeLog("Invalid trades fetch data line:"+tradeData,2);

                if(n==0&&lastTickerDate<newItem.date)
                {
                    lastTickerDate=newItem.date;
                    IndicatorEngine::setValue(baseValues.exchangeName,baseValues.currentPair.symbol,"Last",newItem.price);
                }
            }
            if(newTradesItems->count())emit addLastTrades(baseValues.currentPair.symbol,newTradesItems);
			else delete newTradesItems;
            if(currentTid>1000)lastTradesTid=QByteArray::number(currentTid);
		}
        else if(data!="[]"){
            success=false;
            errorString+="Invalid trades data. ";
        }
		break;//trades
	case 111: //depth
        if(data.startsWith("{\"asks\":[["))
		{
			emit depthRequestReceived();

			if(lastDepthData!=data)
			{
				lastDepthData=data;
				depthAsks=new QList<DepthItem>;
				depthBids=new QList<DepthItem>;

                QMap<double,double> currentAsksMap;
				QStringList asksList=QString(getMidData("asks\":[[","]]",&data)).split("],[");
                double groupedPrice=0.0;
                double groupedVolume=0.0;
				int rowCounter=0;

				for(int n=0;n<asksList.count();n++)
				{
					if(baseValues.depthCountLimit&&rowCounter>=baseValues.depthCountLimit)break;
					QStringList currentPair=asksList.at(n).split(",");
					if(currentPair.count()!=2)continue;
                    double priceDouble=currentPair.first().toDouble();
                    double amount=currentPair.last().toDouble();

					if(baseValues.groupPriceValue>0.0)
					{
						if(n==0)
						{
                            emit depthFirstOrder(baseValues.currentPair.symbol,priceDouble,amount,true);
							groupedPrice=baseValues.groupPriceValue*(int)(priceDouble/baseValues.groupPriceValue);
							groupedVolume=amount;
						}
						else
						{
							bool matchCurrentGroup=priceDouble<groupedPrice+baseValues.groupPriceValue;
							if(matchCurrentGroup)groupedVolume+=amount;
							if(!matchCurrentGroup||n==asksList.count()-1)
							{
                                depthSubmitOrder(baseValues.currentPair.symbol,
                                                 &currentAsksMap,groupedPrice+baseValues.groupPriceValue,groupedVolume,true);
								rowCounter++;
								groupedVolume=amount;
								groupedPrice+=baseValues.groupPriceValue;
							}
						}
					}
					else
					{
                        depthSubmitOrder(baseValues.currentPair.symbol,
                                         &currentAsksMap,priceDouble,amount,true);
						rowCounter++;
					}
				}
                QList<double> currentAsksList=lastDepthAsksMap.keys();
				for(int n=0;n<currentAsksList.count();n++)
                    if(currentAsksMap.value(currentAsksList.at(n),0)==0)depthUpdateOrder(baseValues.currentPair.symbol,
                                                                                         currentAsksList.at(n),0.0,true);
				lastDepthAsksMap=currentAsksMap;

                QMap<double,double> currentBidsMap;
				QStringList bidsList=QString(getMidData("bids\":[[","]]",&data)).split("],[");
				groupedPrice=0.0;
				groupedVolume=0.0;
				rowCounter=0;

				for(int n=0;n<bidsList.count();n++)
				{
					if(baseValues.depthCountLimit&&rowCounter>=baseValues.depthCountLimit)break;
					QStringList currentPair=bidsList.at(n).split(",");
					if(currentPair.count()!=2)continue;
                    double priceDouble=currentPair.first().toDouble();
                    double amount=currentPair.last().toDouble();
					if(baseValues.groupPriceValue>0.0)
					{
						if(n==0)
						{
                            emit depthFirstOrder(baseValues.currentPair.symbol,priceDouble,amount,false);
							groupedPrice=baseValues.groupPriceValue*(int)(priceDouble/baseValues.groupPriceValue);
							groupedVolume=amount;
						}
						else
						{
							bool matchCurrentGroup=priceDouble>groupedPrice-baseValues.groupPriceValue;
							if(matchCurrentGroup)groupedVolume+=amount;
							if(!matchCurrentGroup||n==asksList.count()-1)
							{
                                depthSubmitOrder(baseValues.currentPair.symbol,
                                                 &currentBidsMap,groupedPrice-baseValues.groupPriceValue,groupedVolume,false);
								rowCounter++;
								groupedVolume=amount;
								groupedPrice-=baseValues.groupPriceValue;
							}
						}
					}
					else
					{
                        depthSubmitOrder(baseValues.currentPair.symbol,
                                         &currentBidsMap,priceDouble,amount,false);
						rowCounter++;
					}
				}
                QList<double> currentBidsList=lastDepthBidsMap.keys();
				for(int n=0;n<currentBidsList.count();n++)
                    if(currentBidsMap.value(currentBidsList.at(n),0)==0)depthUpdateOrder(baseValues.currentPair.symbol,
                                                                                         currentBidsList.at(n),0.0,false);
				lastDepthBidsMap=currentBidsMap;

                emit depthSubmitOrders(baseValues.currentPair.symbol,depthAsks, depthBids);
				depthAsks=0;
				depthBids=0;
			}
		}
        else {
            success=false;
            errorString+="Invalid depth data. ";
            if(debugLevel)logThread->writeLog("Invalid depth data:"+data,2);
        }
		break;
	case 202: //info
        if(data.startsWith("{\"success\":true,\"data\":{\"balances\":{\"available\":"))
        {
            QByteArray fundsData=getMidData("available\":{","}",&data)+",";
            QByteArray btcBalance=getMidData("\""+baseValues.currentPair.currAStr+"\":",",",&fundsData);
			if(!btcBalance.isEmpty())
            {
                double newBtcBalance=btcBalance.toDouble();
                if(lastBtcBalance!=newBtcBalance)emit accBtcBalanceChanged(baseValues.currentPair.symbol,newBtcBalance);
				lastBtcBalance=newBtcBalance;
			}

            QByteArray usdBalance=getMidData("\""+baseValues.currentPair.currBStr+"\":",",",&fundsData);
			if(!usdBalance.isEmpty())
			{
                double newUsdBalance=usdBalance.toDouble();
                if(newUsdBalance!=lastUsdBalance)emit accUsdBalanceChanged(baseValues.currentPair.symbol,newUsdBalance);
				lastUsdBalance=newUsdBalance;
			}
		}
        else {
            success=false;
            errorString+="Invalid info data. ";
        }
		break;//info
	case 204://orders
        if(data.startsWith("{\"success\":true,\"data\":{\"buy\":["))
		{
          if(lastOrders!=data){
            lastOrders=data;
            if(data.startsWith("{\"success\":true,\"data\":{\"buy\":[],\"sell\":[]}"))
            {
				emit ordersIsEmpty();
				break;
			}

            QByteArray dataBuy=getMidData("\"buy\":[{","}],",&data)+"},{"+getMidData("\"sell\":[{","}]",&data);
            QStringList ordersList=QString(dataBuy).split("},{");
            if(ordersList.count()==0)return;
            QList<OrderItem> *orders=new QList<OrderItem>;

			for(int n=0;n<ordersList.count();n++)
			{
				OrderItem currentOrder;
                QByteArray currentOrderData=ordersList.at(n).toLatin1()+"}";

                currentOrder.oid=getMidData("\"id\":",",",&currentOrderData);
                currentOrder.date=getMidData("\"time\":","}",&currentOrderData).toUInt();
                currentOrder.type=getMidData("\"type\":\"","\"",&currentOrderData)=="sell";
                currentOrder.amount=getMidData("\"amount\":",",",&currentOrderData).toDouble();
                currentOrder.price=getMidData("\"rate\":",",",&currentOrderData).toDouble();
                currentOrder.symbol=getMidData("\"market\":\"","\"",&currentOrderData);
                currentOrder.status=1;
				if(currentOrder.isValid())(*orders)<<currentOrder;
			}
            emit orderBookChanged(baseValues.currentPair.symbol,orders);
          }
		}
        else {
            success=false;
            errorString+="Invalid orders data. ";
        }
		break;//orders
	case 305: //order/cancel
		{
            if(!cancelingOrderIDs.isEmpty())
            {
                if(data.startsWith("{\"success\":true"))emit orderCanceled(baseValues.currentPair.symbol,cancelingOrderIDs.first());
                if(debugLevel)logThread->writeLog("Order canceled:"+cancelingOrderIDs.first(),2);
                cancelingOrderIDs.removeFirst();
            }

            dataReceivedAuth(data,202);
        }
		break;//order/cancel
    case 306:
        {
            if(debugLevel)logThread->writeLog("Buy OK: "+data,2);
            if(data.startsWith("{\"error\"")){
                success=false;
                errorString+="Invalid order/buy data. ";
            }
        }
        break;//order/buy
    case 307:
        {
            if(debugLevel)logThread->writeLog("Sell OK: "+data,2);
            if(data.startsWith("{\"error\"")){
                success=false;
                errorString+="Invalid order/sell data. ";
            }
        }
        break;//order/sell
    case 208: ///history
        if(data.startsWith("{\"success\":true,\"data\":{\"total\":"))
        {
            QByteArray historyData=getMidData("\"results\":[{","}]}",&data)+"^";
            if(lastHistory!=historyData)
            {
                lastHistory=historyData;
                if(historyData=="^")break;
                QString newLog(historyData);
                QStringList dataList=newLog.split("},{");
                if(dataList.count()==0)return;

                quint32 currentId;
                quint32 maxId=0;
                QList<HistoryItem> *historyItems=new QList<HistoryItem>;
                for(int n=0;n<dataList.count();n++)
                {
                    QByteArray curLog(dataList.at(n).toLatin1());

                    currentId=getMidData("id\":",",",&curLog).toUInt();
                    if(currentId<=lastHistoryId)break;
                    if(n==0)maxId=currentId;

                    HistoryItem currentHistoryItem;
                    QByteArray logType=getMidData("type\":\"","\"",&curLog);
                    if(logType=="sell")currentHistoryItem.type=1;else if(logType=="buy")currentHistoryItem.type=2;
                    if(currentHistoryItem.type)
                    {
                        currentHistoryItem.symbol=getMidData("currencyCrypto\":\"","\"",&curLog)+getMidData("currencyFiat\":\"","\"",&curLog);
                        currentHistoryItem.dateTimeInt=getMidData("time\":",",",&curLog).toUInt();
                        currentHistoryItem.price=getMidData("rate\":",",",&curLog).toDouble();
                        currentHistoryItem.volume=getMidData("amountCrypto\":",",",&curLog).toDouble();

                        if(currentHistoryItem.isValid())(*historyItems)<<currentHistoryItem;
                    }
                }
                if(maxId>lastHistoryId)lastHistoryId=maxId;
                emit historyChanged(historyItems);
            }
        }
        else {
            success=false;
            errorString+="Invalid history data. ";
        }
		break;//money/wallet/history
	default: break;
	}

    static int errorCount=0;
	if(!success)
    {
        errorCount++;if(errorCount<2)return;
        QByteArray errorMsg=getMidData("errorMsg\":\"","\"",&data);errorString+="Error message: "+errorMsg;
		if(debugLevel)logThread->writeLog("API error: "+errorString.toLatin1()+" ReqType:"+QByteArray::number(reqType),2);
        if(errorMsg=="Invalid nonce value"||errorMsg=="")return;
        emit showErrorMessage("I:>"+errorString);
	}
    else errorCount=0;
}
コード例 #6
0
ファイル: focus.cpp プロジェクト: monisha4/kstars-hackfest
void Focus::clearLog()
{
    logText.clear();
    emit newLog();
}
コード例 #7
0
ファイル: chatserver.cpp プロジェクト: Wene/test-server
void ChatServer::forwardLog(QString sMessage)
{
    emit newLog(sMessage);
}