ToastNotificationProxy::ToastNotificationProxy(const char* name) : Ti::TiProxy(name)
{

	createPropertySetter("buttonTitle", _setButtonTitle);
	createPropertySetter("icon", _setIcon);
	createPropertySetter("message", _setMessage);
	createPropertySetter("position", _setPosition);
	createPropertySetter("modality", _setModality);

	createPropertyFunction("show", _show);
	createPropertyFunction("cancel", _cancel);

	_toast = new bb::system::SystemToast();
	_toast->setPosition(bb::system::SystemUiPosition::BottomCenter);

	ToastNotificationEventHandler* eventHandler = new ToastNotificationEventHandler(this);
	eventHandler->setParent(_toast);
	QObject::connect(
			_toast,
			SIGNAL(finished(bb::system::SystemUiResult::Type)),
			eventHandler,
			SLOT(onFinish(bb::system::SystemUiResult::Type))
	);

}
Beispiel #2
0
void Engine::popAll() {
    while(!scenes.empty()) {
        auto scene = scenes.top();
        scene->onFinish();

        delete scene;
        scene = nullptr;

        scenes.pop();
    }
}
ImageLoader::ImageLoader(bb::cascades::ImageView* img, QUrl url)
{
	imageView = img;
	networkManager = new QNetworkAccessManager();
	imageUrl = url;
	if (networkManager)
	{
	    QNetworkRequest networkRequest(url);
	   	networkReply = networkManager->get(networkRequest);
	    connect(networkReply, SIGNAL(finished()), this, SLOT(onFinish()));
	}
}
void VFSDiscSelectorDialog::accept()
{
	if(ui->disc_image_radioButton->isChecked())
	{
		if(!ui->lineEdit->text().isEmpty())
		{
			emit onFinish(ui->lineEdit->text(), CCdrom0Device::BINDING_IMAGE);
			return QDialog::accept();
		}
	}
	else
	{
		if(ui->comboBox->currentIndex() > -1)
		{
			emit onFinish(QString(m_discInfo.at(ui->comboBox->currentIndex()).device()), CCdrom0Device::BINDING_PHYSICAL);
			return QDialog::accept();
		}
	}
	QMessageBox messageBox;
	messageBox.critical(this, "Error", "Invalid selection, please try again.");
	messageBox.show();
}
Beispiel #5
0
void Engine::pop() {
    if(!scenes.empty()) {
        auto scene = scenes.top();
        scenes.pop();

        scene->onFinish();
        delete scene;
        scene = nullptr;

        if(!scenes.empty()) {
            scenes.top()->onResume();
        }
    }
}
Beispiel #6
0
PictureLoader::PictureLoader(Game *game) :
    QObject(game),
    d_ptr(new PictureLoaderPrivate)
{
    Q_D(PictureLoader);

    Q_ASSERT(game);
    Q_ASSERT(game->isValid());

    d->game = game;
    d->manager = new QNetworkAccessManager(d);

    connect(d->manager, SIGNAL(finished(QNetworkReply*)), d, SLOT(save(QNetworkReply*)));
    connect(d, SIGNAL(finished(QString)), SLOT(onFinish(QString)));
}
SunscraperRPC::SunscraperRPC(QLocalSocket *socket) :
        m_socket(socket), m_state(StateHeader), m_result(false)
{
    m_nextQueryId += 1;
    m_queryId = m_nextQueryId;

    connect(m_socket, SIGNAL(readyRead()), this, SLOT(onInputReadable()));
    connect(m_socket, SIGNAL(disconnected()), this, SLOT(onInputDisconnected()));

    if(m_worker == NULL)
        m_worker = new SunscraperWorker();

    connect(m_worker, SIGNAL(finished(uint)), this, SLOT(onFinish(uint)));
    connect(m_worker, SIGNAL(timedOut(uint)), this, SLOT(onTimeout(uint)));
    connect(m_worker, SIGNAL(htmlFetched(uint,QString)), this, SLOT(onFetchDone(uint,QString)));
}
void MatrixLCDImplementation::transfer(uint16_t* address)
{
    // chip select - note the LCD is active high
    cs = 1;

    // use local transfer done function to deselect CS pin before calling external callback
    SPI::event_callback_t onFinish(this, &MatrixLCDImplementation::transferDone);

    // send buffer over SPI
    spi.transfer()
        .tx(address, (LCD_Height_Rows*LCD_Stride_Bytes + LCD_End_Padding) / 2)
        .callback(onFinish, SPI_EVENT_ALL)
        .apply();

    // call external callback signaling transfer has begun
    if (onTransferBegin)
    {
        onTransferBegin.call();
    }
}
//refactoring multithread downloading
void * MyDownload::run(void *)
{
	unsigned long temp = 0;
	unsigned long *downloaded = &temp;
	unsigned long totalSize = 1024;
	bool ret;

	while (downloadListRemoteURLs.size()>0)
	{
		cout << downloadListRemoteURLs[0] << endl;
		//default thread number is 3. The number can be changed but must be consistent.
		while (true) {
			//loop until the task is finished.
			ret = DownloadHelper(downloadListRemoteURLs[0].data(),
				downloadListLocalFolders[0].data(), downloaded, totalSize, THREAD_COUNT);
			if (ret) {
				cout << "True" << endl;
			}
			if (!exist(0)) {
				//file doesn't exist.
				cout << "Task failed,reconnecting..." << endl;
				Sleep(RECONNECT_INTERVAL);	//reconnecting after 10 seconds.
			}
			else {
				//download finished. delete the first task.
				vector<string>::iterator startIterator = downloadListRemoteURLs.begin();
				downloadListRemoteURLs.erase(startIterator);
				startIterator = downloadListLocalFolders.begin();
				downloadListLocalFolders.erase(startIterator);
				break;
			}
		}
	}
	if (onFinish != NULL) {
		onFinish();
	}
	return NULL;
}
void BlockDataManagerThread::run()
try
{
   BlockDataManager_LevelDB *const bdm = this->bdm();
   BlockDataViewer *const bdv = this->bdv();
   
   BDM_CallBack *const callback = pimpl->callback;

   OnFinish onFinish(
      [callback] () { callback->run(BDMAction_Exited, nullptr); }
   );
   
   {
      tuple<BDMPhase, double, unsigned, unsigned> lastvalues;
      time_t lastProgressTime=0;
      
      class BDMStopRequest
      {
      public:
         virtual ~BDMStopRequest() { }
      };
     
      const auto loadProgress
         = [&] (BDMPhase phase, double prog,unsigned time, unsigned numericProgress)
      {
         const tuple<BDMPhase, double, unsigned, unsigned> currentvalues
            { phase, prog, time, numericProgress };
         if (currentvalues == lastvalues)
            return; // don't go to python if nothing's changed
         
         // also, don't go to the python if the phase is the same and it's been
         // less than 1 second since the last time this has been called
         // python is a lot slower than C++, so we don't want to invoke
         // the python interpreter to frequently
         const time_t currentProgressTime = std::time(nullptr);
         if (phase == get<0>(lastvalues)
            && currentProgressTime <= lastProgressTime+1
            && fabs(get<1>(lastvalues)-get<1>(currentvalues)) <= .01 )
            return;
            
         lastProgressTime = currentProgressTime;
         
         lastvalues = currentvalues;
         
         //pass empty walletID for main build&scan calls
         callback->progress(phase, vector<string>(), prog, time, numericProgress);

         if (!pimpl->run)
         {
            LOGINFO << "Stop requested detected";
            throw BDMStopRequest();
         }
         
      };
      
      try
      {
         //don't call this unless you're trying to get online
         pimpl->bdm->setNotifier(pimpl->inject);

         bdm->openDatabase();

         unsigned mode = pimpl->mode & 0x00000003;
         bool clearZc = pimpl->mode & 0x00000004;

         if (mode == 0) bdm->doInitialSyncOnLoad(loadProgress);
         else if (mode == 1) bdm->doInitialSyncOnLoad_Rescan(loadProgress);
         else if (mode == 2) bdm->doInitialSyncOnLoad_Rebuild(loadProgress);

         if (bdm->missingBlockHashes().size() || bdm->missingBlockHeaderHashes().size())
         {
            string errorMsg(
               "Armory has detected an error in the blockchain database "
               "maintained by the third-party Bitcoin software (Bitcoin-Qt "
               "or bitcoind). This error is not fatal, but may lead to "
               "incorrect balances, inability to send coins, or application "
               "instability."
               "<br><br> "
               "It is unlikely that the error affects your wallets, "
               "but it <i>is</i> possible. If you experience crashing, "
               "or see incorrect balances on any wallets, it is strongly "
               "recommended you re-download the blockchain using: "
               "<i>Help</i>\"\xe2\x86\x92\"<i>Factory Reset</i>\".");
            callback->run(BDMAction_ErrorMsg, &errorMsg, bdm->missingBlockHashes().size());
            throw;
         }

         bdv->enableZeroConf(clearZc);

         bdv->scanWallets();
      }
      catch (BDMStopRequest&)
      {
         LOGINFO << "UI asked build/scan thread to finish";
         return;
      }
   }
   
   double lastprog=0;
   unsigned lasttime=0;
   
   const auto rescanProgress
      = [&] (const vector<string>& wltIdVec, double prog,unsigned time)
   {
      if (prog == lastprog && time==lasttime)
         return; // don't go to python if nothing's changed
      //callback->progress("blk", prog, time);
      lastprog = prog;
      lasttime = time;
      
      callback->progress(
         BDMPhase_Rescan,
         wltIdVec,
         lastprog, lasttime, 0
      );
   };   
   
   //push 'bdm is ready' to Python
   callback->run(BDMAction_Ready, nullptr, bdm->getTopBlockHeight());
   
   while(pimpl->run)
   {
      bdm->getScrAddrFilter()->checkForMerge();

      if (bdm->sideScanFlag_ == true)
      {
         bdm->sideScanFlag_ = false;

         bool doScan = bdm->startSideScan(rescanProgress);
         
         vector<string> wltIDs = bdm->getNextWalletIDToScan();
         if (wltIDs.size() && doScan)
         {
            callback->run(BDMAction_StartedWalletScan, &wltIDs);
         }
      }

      if (bdm->criticalError_.size())
      {
         throw runtime_error(bdm->criticalError_.c_str());
      }

      if(bdv->rescanZC_)
      {
         bdv->rescanZC_ = false;
         if (bdv->parseNewZeroConfTx() == true)
         {
            set<BinaryData> newZCTxHash = bdv->getNewZCTxHash();
            bdv->scanWallets();

            vector<LedgerEntry> newZCLedgers;

            for (const auto& txHash : newZCTxHash)
            {
               auto& le_w = bdv->getTxLedgerByHash_FromWallets(txHash);
               if (le_w.getTxTime() != 0)
                  newZCLedgers.push_back(le_w);

               auto& le_lb = bdv->getTxLedgerByHash_FromLockboxes(txHash);
               if (le_lb.getTxTime() != 0)
                  newZCLedgers.push_back(le_lb);
            }

            LOGINFO << newZCLedgers.size() << " new ZC Txn";
            //notify ZC
            callback->run(BDMAction_ZC, &newZCLedgers);
         }
      }

      if (bdv->refresh_ != BDV_dontRefresh)
      {
         unique_lock<mutex> lock(bdv->refreshLock_);

         BDV_refresh refresh = bdv->refresh_;
         bdv->refresh_ = BDV_dontRefresh;
         bdv->scanWallets(UINT32_MAX, UINT32_MAX, refresh);
         
         vector<BinaryData> refreshIDVec;
         for (const auto& refreshID : bdv->refreshIDSet_)
            refreshIDVec.push_back(refreshID);

         bdv->refreshIDSet_.clear();
         callback->run(BDMAction_Refresh, &refreshIDVec);
      }

      const uint32_t prevTopBlk = bdm->readBlkFileUpdate();
      if(prevTopBlk > 0)
      {
         bdv->scanWallets(prevTopBlk);

         //notify Python that new blocks have been parsed
         int nNewBlocks = bdm->blockchain().top().getBlockHeight() + 1
            - prevTopBlk;
         callback->run(BDMAction_NewBlock, &nNewBlocks,
            bdm->getTopBlockHeight()
         );
      }
      
#ifndef _DEBUG_REPLAY_BLOCKS
      pimpl->inject->wait(1000);
#endif
   }
}
catch (std::exception &e)
{
   LOGERR << "BDM thread failed: " << e.what();
   string errstr(e.what());
   pimpl->callback->run(BDMAction_ErrorMsg, &errstr);
   pimpl->inject->setFailureFlag();
   pimpl->inject->notify();
}
catch (...)
{
   LOGERR << "BDM thread failed: (unknown exception)";
   pimpl->inject->setFailureFlag();
   pimpl->inject->notify();
}
Beispiel #11
0
void SelfBState::update()
{
    mFinished = true;
    onFinish();
}