KexiFindDialog::KexiFindDialog(QWidget* parent)
        : QDialog(parent,
                  Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::Tool)
        , d(new Private())
{
    setObjectName("KexiFindDialog");
    setupUi(this);
    m_search->setCurrentIndex(
        (int)KexiSearchAndReplaceViewInterface::Options::SearchDown);
    layout()->setMargin(KDialog::marginHint());
    layout()->setSpacing(KDialog::spacingHint());
    QAction *a = KStandardAction::findNext(0, 0, 0);
    m_btnFind->setText(a->text());
    m_btnFind->setIcon(a->icon());
    delete a;
    m_btnClose->setText(KStandardGuiItem::close().text());
    m_btnClose->setIcon(KStandardGuiItem::close().icon());
    connect(m_btnFind, SIGNAL(clicked()), this, SIGNAL(findNext()));
    connect(m_btnClose, SIGNAL(clicked()), this, SLOT(slotCloseClicked()));
    connect(m_btnReplace, SIGNAL(clicked()), this, SIGNAL(replaceNext()));
    connect(m_btnReplaceAll, SIGNAL(clicked()), this, SIGNAL(replaceAll()));
    // clear message after the text is changed
    connect(m_textToFind, SIGNAL(editTextChanged(QString)), this, SLOT(updateMessage(QString)));
    connect(m_textToReplace, SIGNAL(editTextChanged(QString)), this, SLOT(updateMessage(QString)));

    d->replaceMode = true; //to force updating by setReplaceMode()
    setReplaceMode(false);

    setLookInColumnList(QStringList(), QStringList());
}
bool CWizDatabase::updateMessages(const CWizMessageDataArray& arrayMsg)
{
    // TODO: delete messages not exist on remote
    if (arrayMsg.empty())
        return false;

    qint64 nVersion = -1;

    bool bHasError = false;
    CWizMessageDataArray::const_iterator it;
    for (it = arrayMsg.begin(); it != arrayMsg.end(); it++)
    {
        const WIZMESSAGEDATA& msg = *it;
        if (!updateMessage(msg)) {
            bHasError = true;
        }

        nVersion = qMax(nVersion, msg.nVersion);
    }

    if (!bHasError) {
        SetObjectVersion(WIZMESSAGEDATA::ObjectName(), nVersion);
    }

    return !bHasError;
}
Beispiel #3
0
/* Create a file, including parent directory as necessary. */
void QArchive::createFile(const QString& pathname, int /*mode*/)
{
	Q_D(QArchive);
#if CONFIG_QT4
	d->outFile.setFileName(d->outDir+"/"+pathname);
	if(!d->outFile.open(QIODevice::ReadWrite)) {
#else
	d->outFile.setName(d->outDir+"/"+pathname);
	if(!d->outFile.open(IO_ReadWrite)) {
#endif
		ezDebug(d->outDir+"/"+pathname);
		if(pathname.left(1)=="/") {
			QDir(d->outDir).mkdir(pathname.mid(1));
		} else	QDir(d->outDir).mkdir(pathname);
	} else {
#if CONFIG_QT4
		//d->outFile.setPermissions();
#endif
	}
}

void QArchive::timerEvent(QTimerEvent *)
{
	updateMessage();//estimate();
	checkTryPause();
}
Beispiel #4
0
void QArchive::forceShowMessage(int interval)
{
	Q_D(QArchive);
	if(d->time.elapsed()-d->time_passed>interval) {
		d->time_passed = d->time.elapsed();
		updateMessage();
	}
}
void
ScreenWindow::_UpdateMonitorView()
{
	BMessage updateMessage(UPDATE_DESKTOP_MSG);
	updateMessage.AddInt32("width", fSelected.width);
	updateMessage.AddInt32("height", fSelected.height);

	PostMessage(&updateMessage, fMonitorView);
}
Beispiel #6
0
void QuickHelpCursor::previousMessage()
{
	if (mCurrentPosition != mQuickHelp.getBeginning())
	{
		mCursorLocation--;
		mCurrentPosition--;
		updateMessage();
	}
}
Beispiel #7
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void VolumeMesh::progressMessage(AIM_STRING message, int progress)
{
#ifdef DREAM3D_USE_QT
      emit updateMessage(QString(message));
      emit updateProgress(progress);
     // std::cout << message.toStdString() << std::endl;
#else
  std::cout << message << std::endl;
#endif
}
void NotificationDialog::changeEvent(QEvent *event)
{
	QFrame::changeEvent(event);

	if (event->type() == QEvent::LanguageChange)
	{
		m_closeLabel->setToolTip(tr("Close"));

		updateMessage();
	}
}
CheckUpdatesWorker::CheckUpdatesWorker(ProgramOptions *programOptions, QWidget *parentForm, QLabel *caption,
									   QProgressBar *progressBar, QAbstractButton *cancelButton, bool isUser)
	: QObject()
{
	this->programOptions = programOptions;
	this->parentForm = parentForm;
	this->caption = caption;
	this->progressBar = progressBar;
	this->cancelButton = cancelButton;
	this->isUser = isUser;
	// init updater
	updates = new Updates(programOptions->getApplicationPath());
	// signals
	connect(updates, SIGNAL(progressCheckUpdate(int)), this, SLOT(progressCheckUpdate(int)));
	connect(updates, SIGNAL(updatesChecked(bool)), this, SLOT(updatesChecked(bool)));
	connect(updates, SIGNAL(updatesCancelled()), this, SLOT(updatesCancelled()));
	connect(updates, SIGNAL(updateMessage(QString, QString)), this, SLOT(updateMessage(QString, QString)));
	//
	connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
}
Beispiel #10
0
void MainWindow::connectEvents() {
    handler = new ctkEventDemo();
    connect(ui->btnSend, SIGNAL(released()), this, SLOT(sendEvent()));
    connect(handler, SIGNAL(updateMessageSignal(QString)), this, SLOT(updateMessage(QString)));
    connect(ui->connectButton, SIGNAL(released()), this, SLOT(connectClient()));

    qDebug() << "connectEvents";
    m_EventBus->publishSignal(handler, "receiveEventSignal(QVariantList)", "ctk/remote/eventBus/comunication/receive/xmlrpc");
    ctkDictionary dic;
    dic.insert("event.topics","ctk/remote/eventBus/comunication/receive/xmlrpc");
    m_EventBus->subscribeSlot(handler, "receiveEvent(QVariantList)", dic);
}
Beispiel #11
0
QuickHelpCursor::QuickHelpCursor() : mQuickHelp(Gui::QuickHelp::getSingleton())
{
	mQuickHelp.EventHelpMessageAdded.connect(sigc::mem_fun(*this, &QuickHelpCursor::getLatestHelpMessage));
	mQuickHelp.EventHelpMessageLocationChanged.connect(sigc::mem_fun(*this, &QuickHelpCursor::setCursorLocation));

	mCursorLocation = getSize();
	mCurrentPosition = mQuickHelp.getEnd();
	if (mCursorLocation > 0) {
		mCurrentPosition--;
		updateMessage();
	}
}
/*!

*/
void
DebugMessageWindow::decrementCycle()
{
    if ( ! M_main_data.getDebugLogHolder().decDataCycle( M_tab_widget->currentIndex() + 1 ) )
    {
        return;
    }

    updateMessage();

    emit selectCycle( M_main_data.getDebugLogHolder().getCurrentCycle() );
}
Beispiel #13
0
void
BeliefProp::maxResidualSchedule (void)
{
  if (nIters_ == 1) {
    for (size_t i = 0; i < links_.size(); i++) {
      calculateMessage (links_[i]);
      SortedOrder::iterator it = sortedOrder_.insert (links_[i]);
      linkMap_.insert (make_pair (links_[i], it));
    }
    return;
  }

  for (size_t c = 0; c < links_.size(); c++) {
    if (Globals::verbosity > 1) {
      cout << "current residuals:" << endl;
      for (SortedOrder::iterator it = sortedOrder_.begin();
          it != sortedOrder_.end(); ++it) {
        cout << "    " << setw (30) << left << (*it)->toString();
        cout << "residual = " << (*it)->residual() << endl;
      }
    }

    SortedOrder::iterator it = sortedOrder_.begin();
    BpLink* link = *it;
    if (link->residual() < BpOptions::accuracy) {
      return;
    }
    updateMessage (link);
    link->clearResidual();
    sortedOrder_.erase (it);
    linkMap_.find (link)->second = sortedOrder_.insert (link);

    // update the messages that depend on message source --> destin
    const FacNodes& factorNeighbors = link->varNode()->neighbors();
    for (size_t i = 0; i < factorNeighbors.size(); i++) {
      if (factorNeighbors[i] != link->facNode()) {
        const BpLinks& links = ninf(factorNeighbors[i])->getLinks();
        for (size_t j = 0; j < links.size(); j++) {
          if (links[j]->varNode() != link->varNode()) {
            calculateMessage (links[j]);
            BpLinkMap::iterator iter = linkMap_.find (links[j]);
            sortedOrder_.erase (iter->second);
            iter->second = sortedOrder_.insert (links[j]);
          }
        }
      }
    }
    if (Globals::verbosity > 1) {
      Util::printDashedLine();
    }
  }
}
/*!

*/
void
DebugMessageWindow::incrementCycle()
{
    if ( ! M_main_data.getDebugLogHolder().incDataCycle( M_tab_widget->currentIndex() + 1 ) )
    {
        std::cerr << "Failed increment debug log" << std::endl;
        return;
    }

    updateMessage();

    emit selectCycle( M_main_data.getDebugLogHolder().getCurrentCycle() );
}
Beispiel #15
0
void QuickHelpCursor::nextMessage()
{
	if (getSize()) {
		//list.end() returns an iterator that is one past the front of the list, so we have a bit of extra work
		mCurrentPosition++;
		if (mCurrentPosition != mQuickHelp.getEnd())
		{
			mCursorLocation++;
			updateMessage();
		} else {
			mCurrentPosition--;
		}
	}
}
void StatusRootAction::showEditStatusDialog()
{
	if ( d->statusDialog ) {
		d->statusDialog->activateWindow();
		return;
	}
	d->statusDialog = new Kopete::UI::StatusEditDialog( Kopete::UI::Global::mainWidget() );
	connect( d->statusDialog, SIGNAL(finished(int)), SLOT(editStatusDialogFinished(int)) );

	if ( d->account ) {
		d->statusDialog->setStatusMessage( d->account->myself()->statusMessage() );
	} else {
		emit updateMessage( this );
	}

	d->statusDialog->exec();
}
Beispiel #17
0
void
BeliefProp::runSolver (void)
{
  initializeSolver();
  nIters_ = 0;
  while (!converged() && nIters_ < BpOptions::maxIter) {
    nIters_ ++;
    if (Globals::verbosity > 1) {
      Util::printHeader (string ("Iteration ") + Util::toString (nIters_));
    }
    switch (BpOptions::schedule) {
     case BpOptions::Schedule::SEQ_RANDOM:
       std::random_shuffle (links_.begin(), links_.end());
       // no break
      case BpOptions::Schedule::SEQ_FIXED:
        for (size_t i = 0; i < links_.size(); i++) {
          calculateAndUpdateMessage (links_[i]);
        }
        break;
      case BpOptions::Schedule::PARALLEL:
        for (size_t i = 0; i < links_.size(); i++) {
          calculateMessage (links_[i]);
        }
        for (size_t i = 0; i < links_.size(); i++) {
          updateMessage(links_[i]);
        }
        break;
      case BpOptions::Schedule::MAX_RESIDUAL:
        maxResidualSchedule();
        break;
    }
  }
  if (Globals::verbosity > 0) {
    if (nIters_ < BpOptions::maxIter) {
      cout << "Belief propagation converged in " ; 
      cout << nIters_ << " iterations" << endl;
    } else {
      cout << "The maximum number of iterations was hit, terminating..." ;
      cout << endl;
    }
    cout << endl;
  }
  runned_ = true;
}
uint32
FSClipboardRemovePoses(const node_ref *directory, PoseList *list)
{
	if (!be_clipboard->Lock())
		return 0;

	// update message to be send to all listeners
	BMessage updateMessage(kFSClipboardChanges);
	updateMessage.AddInt32("device", directory->device);
	updateMessage.AddInt64("directory", directory->node);
	updateMessage.AddBool("clearClipboard", false);

	TClipboardNodeRef clipNode;
	clipNode.moveMode = kDelete;

	uint32 refsRemoved = 0;

	BMessage *clip = be_clipboard->Data();
	if (clip != NULL) {
		int32 listCount = list->CountItems();

		for (int32 index = 0; index < listCount; index++) {
			char refName[64], modeName[64];
			BPose *pose = (BPose *)list->ItemAt(index);

			clipNode.node = *pose->TargetModel()->NodeRef();
			MakeRefName(refName, &clipNode.node);
			MakeModeName(modeName);

			if (clip->RemoveName(refName) == B_OK && clip->RemoveName(modeName)) {
				updateMessage.AddData("tcnode", T_CLIPBOARD_NODE, &clipNode,
					sizeof(TClipboardNodeRef), true, listCount);
				refsRemoved++;
			}
		}
		be_clipboard->Commit();
	}
	be_clipboard->Unlock();

	BMessenger(kTrackerSignature).SendMessage(&updateMessage);
		// Tracker will notify all listeners

	return refsRemoved;
}
/*!

*/
void
DebugMessageWindow::toggleDebugLevel( int level )
{
    //M_level ^= DebugLogData::LEVEL_1; // reverse only 1 bit

    if ( level < 1 || 32 < level )
    {
        std::cerr << "Invalid level " << level << std::endl;
        return;
    }

    int level_flag = 1 << ( level - 1 );

    M_main_data.getDebugLogHolder().setLevel( level_flag,
                                              M_debug_level_act[level-1]->isChecked() );

    updateMessage();
    emit configured();
}
status_t
LocaleRosterData::SetFilesystemTranslationPreferred(bool preferred)
{
	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	_SetFilesystemTranslationPreferred(preferred);

	status_t status = _SaveLocaleSettings();

	if (status == B_OK) {
		BMessage updateMessage(B_LOCALE_CHANGED);
		status = _AddFilesystemTranslationPreferenceToMessage(&updateMessage);
		if (status == B_OK)
			status = be_roster->Broadcast(&updateMessage);
	}

	return status;
}
Beispiel #21
0
void Client::SetTargetObject(gemObject* newobject, bool updateClientGUI)
{
    // We don't want to fire a target change event if the target hasn't changed.
    if (newobject == target)
        return;

    target = newobject;

    gemActor * myactor = GetActor();
    if (myactor)
    {
        psTargetChangeEvent targetevent( myactor, newobject );
        targetevent.FireEvent();
    }

    if (updateClientGUI)
    {
        psGUITargetUpdateMessage updateMessage(GetClientNum(), newobject? newobject->GetEID() : 0);
        updateMessage.SendMessage();
    }
}
/*!

*/
void
DebugMessageWindow::syncCycle()
{
    MonitorViewConstPtr ptr = M_main_data.getCurrentViewData();
    if ( ! ptr )
    {
        //std::cerr << "sync debug cycle. no view data." << std::endl;
        return;
    }

    std::cerr << "sync debug data cycle" << std::endl;
    // seek current cycle data
    if ( ! M_main_data.getDebugLogHolder().seekData( M_tab_widget->currentIndex() + 1, ptr->cycle() ) )
    {
        std::cerr << "No data! number = "
                  << M_tab_widget->currentIndex() + 1
                  << std::endl;
        return;
    }

    updateMessage();
}
status_t
LocaleRosterData::SetPreferredLanguages(const BMessage* languages)
{
	status_t status = B_OK;

	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	status = _SetPreferredLanguages(languages);

	if (status == B_OK)
		status = _SaveLocaleSettings();

	if (status == B_OK) {
		BMessage updateMessage(B_LOCALE_CHANGED);
		status = _AddPreferredLanguagesToMessage(&updateMessage);
		if (status == B_OK)
			status = be_roster->Broadcast(&updateMessage);
	}

	return status;
}
status_t
LocaleRosterData::SetDefaultTimeZone(const BTimeZone& newZone)
{
	status_t status = B_OK;

	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	status = _SetDefaultTimeZone(newZone);

	if (status == B_OK)
		status = _SaveTimeSettings();

	if (status == B_OK) {
		BMessage updateMessage(B_LOCALE_CHANGED);
		status = _AddDefaultTimeZoneToMessage(&updateMessage);
		if (status == B_OK)
			status = be_roster->Broadcast(&updateMessage);
	}

	return status;
}
status_t
LocaleRosterData::SetDefaultFormattingConventions(
	const BFormattingConventions& newFormattingConventions)
{
	status_t status = B_OK;

	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	status = _SetDefaultFormattingConventions(newFormattingConventions);

	if (status == B_OK)
		status = _SaveLocaleSettings();

	if (status == B_OK) {
		BMessage updateMessage(B_LOCALE_CHANGED);
		status = _AddDefaultFormattingConventionsToMessage(&updateMessage);
		if (status == B_OK)
			status = be_roster->Broadcast(&updateMessage);
	}

	return status;
}
NotificationDialog::NotificationDialog(Notification *notification, QWidget *parent) : QFrame(parent),
	m_notification(notification),
	m_closeLabel(new QLabel(this)),
	m_iconLabel(new QLabel(this)),
	m_messageLabel(new QLabel(this)),
	m_closeTimer(0)
{
	m_iconLabel->setStyleSheet(QLatin1String("padding:5px;"));
	m_iconLabel->setAttribute(Qt::WA_TransparentForMouseEvents);

	m_messageLabel->setStyleSheet(QLatin1String("padding:5px;font-size:13px;"));
	m_messageLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
	m_messageLabel->setWordWrap(true);

	QStyleOption option;
	option.rect = QRect(0, 0, 16, 16);
	option.state = (QStyle::State_Enabled | QStyle::State_AutoRaise);

	QPixmap pixmap(16, 16);
	pixmap.fill(Qt::transparent);

	QPainter painter(&pixmap);

	style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &option, &painter, this);

	m_closeLabel->setToolTip(tr("Close"));
	m_closeLabel->setPixmap(pixmap);
	m_closeLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
	m_closeLabel->setAlignment(Qt::AlignTop);
	m_closeLabel->setMargin(5);

	QBoxLayout *layout(new QBoxLayout(QBoxLayout::LeftToRight));
	layout->setContentsMargins(0, 0, 0, 0);
	layout->setSpacing(0);
	layout->setSizeConstraint(QLayout::SetMinimumSize);
	layout->addWidget(m_iconLabel);
	layout->addWidget(m_messageLabel);
	layout->addWidget(m_closeLabel);

	setLayout(layout);
	setObjectName(QLatin1String("notificationFrame"));
	setStyleSheet(QLatin1String("#notificationFrame {padding:5px;border:1px solid #CCC;border-radius:10px;background:#F0F0f0;}"));
	setCursor(QCursor(Qt::PointingHandCursor));
	setFixedWidth(400);
	setMinimumHeight(50);
	setMaximumHeight(150);
	setWindowOpacity(0);
	setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Tool | Qt::FramelessWindowHint);
	setFocusPolicy(Qt::NoFocus);
	setAttribute(Qt::WA_DeleteOnClose, true);
	setAttribute(Qt::WA_ShowWithoutActivating, true);
	updateMessage();
	adjustSize();

	m_animation = new QPropertyAnimation(this, QStringLiteral("windowOpacity").toLatin1());
	m_animation->setDuration(500);
	m_animation->setStartValue(0.0);
	m_animation->setEndValue(1.0);
	m_animation->start();

	const int visibilityDuration(SettingsManager::getOption(SettingsManager::Interface_NotificationVisibilityDurationOption).toInt());

	if (visibilityDuration > 0)
	{
		m_closeTimer = startTimer(visibilityDuration * 1000);
	}

	connect(notification, &Notification::modified, this, &NotificationDialog::updateMessage);
	connect(notification, &Notification::requestedClose, this, &NotificationDialog::close);
}
Beispiel #27
0
Error QTar::extract()
{
	//ifstream ofstream to seekg()
	QArchive::extract();

	if(!exists()) return Archive::OpenError;
	char buff[Header::RecordSize];
	//QFile outFile;
	//FILE* f;
	size_t bytes_read;
	unsigned int filesize;

#if ARCREADER_QT4
	if(!open(QIODevice::ReadOnly)) {
		error();
#else
	if(open(IO_ReadOnly)) {
		qDebug("open error");
#endif //ARCREADER_QT4
		return Archive::OpenError;
	}
	Q_D(QArchive);
	for (;;) {
#if ARCREADER_QT4
		bytes_read = read(buff,Header::RecordSize);
#else
		bytes_read = readBlock(buff,Header::RecordSize);
#endif //ARCREADER_QT4
		//put them here
		emit byteProcessed(d->processedSize+=Header::RecordSize);
		d->current_fileName=QFileInfo(buff).fileName();

		if (bytes_read < Header::RecordSize) {
			fprintf(stderr,"Short read. expected 512, got %d\n", bytes_read);
			return Archive::ReadError;
		}
		if (isEndBuff(buff)) {
#if USE_SLOT
			emit byteProcessed(d->processedSize+=Header::RecordSize);  //header;
#else
			estimate();
			progressHandler->Progress(d->current_fileName, d->size, d->processedSize+=Header::RecordSize, d->totalSize, d->speed, d->elapsed, d->left);
#endif
			finishMessage();
			return End;
		}
		if (!verifyChecksum(buff)) {
			fprintf(stderr, "Checksum failure\n");
			return ChecksumError;
		}

		switch (buff[156]) {
		case Header::LinkFlag::kLink :			printf(" Ignoring hardlink %s\n", buff); break;
		case Header::LinkFlag::kSymbolicLink :	printf(" Ignoring symlink %s\n", buff); break; /////////////////////////
		case Header::LinkFlag::kCharacter:		printf(" Ignoring character device %s\n", buff); break;
		case Header::LinkFlag::kBlock:			printf(" Ignoring block device %s\n", buff); break;
		case Header::LinkFlag::kDirectory:
			createDir(QString::fromLocal8Bit(buff), parseOct(buff + 100, 8));
			filesize = 0;
			break;
		case Header::LinkFlag::kFIFO:			printf(" Ignoring FIFO %s\n", buff); break;
		default:
			createFile(QString::fromLocal8Bit(buff), parseOct(buff + 100, 8));
			break;
		}

		++d->numFiles;
		filesize = parseOct(buff + 124, 12);
		d->size = filesize;
#if USE_SLOT
		updateMessage();
#endif
		while (filesize > 0) {
			checkTryPause();
#if ARCREADER_QT4
			bytes_read = read(buff,Header::RecordSize);
#else
			bytes_read = readBlock(buff,Header::RecordSize);
#endif //ARCREADER_QT4
			if (bytes_read < Header::RecordSize) {
				fprintf(stderr,"Short read. Expected 512, got %d\n",bytes_read);
				return Archive::ReadError;
			}
			if (filesize < Header::RecordSize) bytes_read = filesize;
			if (d->outFile.isOpen()) {
#if CONFIG_QT4
				if(d->outFile.write(buff,bytes_read)!=bytes_read) {
					fprintf(stderr, "[%s] %s @%d: Failed to write %s\n",__FILE__,__PRETTY_FUNCTION__,__LINE__,qPrintable(d->outFile.fileName()));
#else
				if(d->outFile.writeBlock(buff,bytes_read)!=bytes_read) {
					fprintf(stderr, "[%s] %s @%d: Failed to write %s\n",__FILE__,__PRETTY_FUNCTION__,__LINE__,qPrintable(d->outFile.name()));
#endif
					d->outFile.close();
				}
				/*if (fwrite(buff, 1, bytes_read, f)!= bytes_read) {
					fprintf(stderr, "Failed write\n");
					fclose(f);
					f = NULL;
				}*/
			}
#if USE_SLOT
			forceShowMessage(1000);
			emit byteProcessed(d->processedSize+=Header::RecordSize);//bytes_read);
#else
			estimate();
			progressHandler->Progress(d->current_fileName, d->size, d->processedSize+=Header::RecordSize, d->totalSize, d->speed, d->elapsed, d->left);
#endif
			filesize -= bytes_read;
		}
		//emit byteProcessed(processedSize+=size);
		if(d->outFile.isOpen()) d->outFile.close();
	}
	close();
}

Archive::Error QTar::extract(const QString& archive,const QString& dir)
{
	setArchive(archive);
	setOutDir(dir);

	return extract();
}
uint32
FSClipboardAddPoses(const node_ref *directory, PoseList *list, uint32 moveMode,
	bool clearClipboard)
{
	uint32 refsAdded = 0;
	int32 listCount = list->CountItems();

	if (listCount == 0 || !be_clipboard->Lock())
		return 0;

	// update message to be send to all listeners
	BMessage updateMessage(kFSClipboardChanges);
	updateMessage.AddInt32("device", directory->device);
	updateMessage.AddInt64("directory", directory->node);
	updateMessage.AddBool("clearClipboard", clearClipboard);

	TClipboardNodeRef clipNode;
	clipNode.moveMode = moveMode;

	if (clearClipboard)
		be_clipboard->Clear();

	BMessage *clip = be_clipboard->Data();
	if (clip != NULL) {
		for (int32 index = 0; index < listCount; index++) {
			char refName[64], modeName[64];
			BPose *pose = (BPose *)list->ItemAt(index);
			Model *model = pose->TargetModel();
			const node_ref *node = model->NodeRef();

			BEntry entry;
			model->GetEntry(&entry);
			if (model->IsVolume()
				|| model->IsRoot()
				|| FSIsTrashDir(&entry)
				|| FSIsDeskDir(&entry))
				continue;

			MakeRefName(refName, node);
			MakeModeNameFromRefName(modeName, refName);

			if (clearClipboard) {
				if (clip->AddInt32(modeName, (int32)moveMode) == B_OK)
					if (clip->AddRef(refName, model->EntryRef()) == B_OK) {
						pose->SetClipboardMode(moveMode);

						clipNode.node = *node;
						updateMessage.AddData("tcnode", T_CLIPBOARD_NODE, &clipNode,
							sizeof(TClipboardNodeRef), true, listCount);

						refsAdded++;
					} else
						clip->RemoveName(modeName);
			} else {
				if (clip->ReplaceInt32(modeName, (int32)moveMode) == B_OK) {
					// replace old mode if entry already exists in clipboard
					if (clip->ReplaceRef(refName, model->EntryRef()) == B_OK) {
						pose->SetClipboardMode(moveMode);

						clipNode.node = *node;
						updateMessage.AddData("tcnode", T_CLIPBOARD_NODE, &clipNode,
							sizeof(TClipboardNodeRef), true, listCount);

						refsAdded++;
					} else {
						clip->RemoveName(modeName);
						
						clipNode.node = *node;
						clipNode.moveMode = kDelete;	// note removing node
						updateMessage.AddData("tcnode", T_CLIPBOARD_NODE, &clipNode,
							sizeof(TClipboardNodeRef), true, listCount);
						clipNode.moveMode = moveMode; // set it back to current value
					}
				} else {
					// add it if it doesn't exist
					if (clip->AddRef(refName, model->EntryRef()) == B_OK
						&& clip->AddInt32(modeName, (int32)moveMode) == B_OK) {
						pose->SetClipboardMode(moveMode);
						
						clipNode.node = *node;
						updateMessage.AddData("tcnode", T_CLIPBOARD_NODE, &clipNode,
							sizeof(TClipboardNodeRef), true, listCount);

						refsAdded++;
					} else {
						clip->RemoveName(modeName);
						clip->RemoveName(refName);
						// here notifying delete isn't needed as node didn't
						// exist in clipboard
					}
				}
			}
		}
		be_clipboard->Commit();
	}	
	be_clipboard->Unlock();

	BMessenger(kTrackerSignature).SendMessage(&updateMessage);
		// Tracker will notify all listeners

	return refsAdded;
}
Beispiel #29
0
int main(){
	int in_game=0;
	int turnPre=0;
	int mode=-1;	 	/*range 1-3*/
	int diff=-1; 		/*range 0-3, 0 if pvp*/
	int timer=-1;		/*range 0, 5, 10, 20*/
	int side=-1;        /*range '0' for white, '1' for black*/
	int all41 = -1;		/* range 0-5 depending on piece */
	char confirm='n';	/*range 'n', 'y'*/
	char modeS[26];
	char diffS[26];
	char timerS[26];
	board *board = createNewGame();
	int timer1 = 0;
	int timer2 = 0;
	int timer3 = 0;
	int timer4 = 0;
	int timer5 = 0;
	int altcounter = 1;
	do{	/*game setup*/
		printf("\nChess v1.0 by nøl / C Gets Degrees\n\n");
		while (mode < 1){
			printf("Please select game mode:\n");
			printf("1. Player versus Player\n");
			printf("2. Player versus Computer\n");
			printf("3. Computer versus Computer\n\n");
			scanf("%d", &mode);
			switch(mode){
				case 1:
					printf("Player versus Player selected\n");
					break;
				case 2:
					printf("Player versus Computer selected\n\n");
					printf("Choose a side: White(0) or Black(1)?\n");
					scanf("%d", &side);
					switch(side){
						case 0:
							printf("White selected\n");
							break;
						case 1:
							printf("Black selected\n");
							break;
						default:
							printe(selection);
							side = -1;
							break;
					}
					break;
				case 3:
					printf("Computer versus Computer selected\n");
					break;
				default:
					printe(selection);
					mode = -1;
					break;
			}
		}
		while (all41 < 0){
			printf("\nPlease select game type. All-for-One mode creates all pieces of the same type!\n");
			printf("0. Standard Chess\n");
			printf("1. All-for-Pawn\n");
			printf("2. All-for-Knight\n");
			printf("3. All-for-Queen\n");
			printf("4. All-for-Rook\n");
			printf("5. All-for-Bishop\n");
			scanf("%d", &all41);
			switch(all41){
				case 0:
					printf("Standard chess selected\n");
					break;
				case 1:
					printf("All-for-Pawn selected\n");
					break;
				case 2:
					printf("All-for-Knight selected\n");
					break;
				case 3:
					printf("All-for-Queen selected\n");
					break;
				case 4:
					printf("All-for-Rook selected\n");
					break;
				case 5:
					printf("All-for-Bishop selected\n");
					break;
				default:
					printe(selection);
					all41 = -1;
					break;
			}
		}
		while (diff < 0){
			if (mode == 1){
				diff = 0;
				break;
			}
			printf("\nPlease select computer difficulty:\n");
			printf("1. Easy\n");
			printf("2. Medium\n");
			printf("3. Hard\n\n");
			scanf("%d", &diff);
			switch(diff){
				case 1:
					printf("Easy selected\n");
					break;
				case 2:
					printf("Medium selected\n");
					break;
				case 3:
					printf("Hard selected\n");
					break;
				default:
					printe(selection);
					diff = -1;
					break;
			}
		}
		while (timer < 0){
			printf("\nPlease select game timer length:\n");
			printf("0. No limit\n");
			printf("5. 5 minutes\n");
			printf("10. 10 minutes\n");
			printf("20. 20 minutes\n\n");
			scanf("%d", &timer);
			switch(timer){
				case 0:
					printf("No limit selected\n");
					timer = 0;
					break;
				case 5:
					printf("5 minutes selected\n");
					timer1 = timer*60;
					timer3 = timer*60;
					break;
				case 10:
					printf("10 minutes selected\n");
					timer1 = timer*60;
					timer3 = timer*60;
					break;
				case 20:
					printf("20 minutes selected\n");
					timer1 = timer*60;
					timer3 = timer*60;
					break;
				default:
					printe(selection);
					timer1 = 0;
					timer3 = 0;
					timer = -1;
					break;
			}
		}
		/*CREATE STRINGS FOR SELECTIONS*/
		switch(mode){
			case 1:
				strcpy(modeS, "Player versus Player");
				break;
			case 2:
				strcpy(modeS, "Player versus Computer");
				break;
			case 3:
				strcpy(modeS, "Computer versus Computer");
				break;
		}
		switch(diff){
			case 0:
				strcpy(diffS, "");
				break;
			case 1:
				strcpy(diffS, "\nDifficulty: Easy");
				break;
			case 2:
				strcpy(diffS, "\nDifficulty: Medium");
				break;
			case 3:
				strcpy(diffS, "\nDifficulty: Hard");
				break;
		}
		switch(timer){
			case 0:
				strcpy(timerS, "No time limit");
				break;
			case 5:
				strcpy(timerS, "5 minutes");
				break;
			case 10:
				strcpy(timerS, "10 minutes");
				break;
			case 20:
				strcpy(timerS, "20 minutes");
				break;
		}
		/*CONFIRM SELECTIONS*/
		printf("\n\nPlease confirm selections: [y/n]\n\n");
		printf("Mode: %s", modeS);
		printf("%s", diffS);
		printf("\nTimer: %s\n\n", timerS);
		scanf(" %c", &confirm);

		if (confirm == 'y' || confirm == 'Y'){
			in_game = 1;
			fgetc(stdin); /* absorb the /n produced by the last scanf */
			createMoveLog();
		}
		else if (confirm == 'n' || confirm == 'N'){
			mode = -1;
			side = -1;
			diff = -1;
			timer = -1;
			all41 = -1;
		}
		else{
			printe(selection);
		}
		
		int aiTeam1, aiTeam2;
		if(mode == 2){ /* Inverts input value 0 -> 1, 1 -> 0, other input will cause assertion failure */
			aiTeam1 = oppTeam(side); /* oppTeam function comes from ai.c. Reads an int, returns an int. */
		}
		if(mode == 3){ /* Default for CPU vs CPU */
			aiTeam1 = 0;
			aiTeam2 = 1;
		}
		
		while(in_game){ /* if side = 1, player is black */
			if (timer != 0){
				/* set up timer */
				if (altcounter % 2 != 0){
					timer5 = timer4 - timer2;
					timer1 = timer1 - timer5;
					altcounter = altcounter+1;
				}
				else{
					timer5 = timer4 - timer2;
					timer3 = timer3 - timer5;
					altcounter = altcounter+1;
				}
				if (timer1 <= 0){
				printf("\nWhite has run out of time!\n");
				exit(0);
				}
				if (timer3 <= 0){
					printf("\nBlack has run out of time!\n");
					exit(0);
				}
			}
			int alpha;
			cell *tmp1;
			switch(all41){
				case 0:
				break;
				case 1:
					for(alpha = 0; alpha <64; alpha++){
						tmp1 = getCell(alpha, board);
						if (tmp1->piece != NULL && tmp1->piece->type != king){
							tmp1->piece->type = pawn;
							updatePrintPiece(tmp1);
						}
					}
					break;
				case 2:
					for(alpha = 0; alpha <64; alpha++){
						tmp1 = getCell(alpha, board);
						if (tmp1->piece != NULL && tmp1->piece->type != king){
							tmp1->piece->type = knight;
							updatePrintPiece(tmp1);
						}
					}
					break;
				case 3:
					for(alpha = 0; alpha <64; alpha++){
						tmp1 = getCell(alpha, board);
						if (tmp1->piece != NULL && tmp1->piece->type != king){
							tmp1->piece->type = queen;
							updatePrintPiece(tmp1);
						}
					}
					break;
				case 4:
					for(alpha = 0; alpha <64; alpha++){
						tmp1 = getCell(alpha, board);
						if (tmp1->piece != NULL && tmp1->piece->type != king){
							tmp1->piece->type = rook;
							updatePrintPiece(tmp1);
						}
					}
					break;
				case 5:
					for(alpha = 0; alpha <64; alpha++){
						tmp1 = getCell(alpha, board);
						if (tmp1->piece != NULL && tmp1->piece->type != king){
							tmp1->piece->type = bishop;
							updatePrintPiece(tmp1);
						}
					}
					break;
			}
			
			turnPre = board->turn;
			timer2 = (int) time(NULL);
			updateGameDisplay(board); /* display the entire board only when its a new turn */
			while (turnPre == board->turn){
				cell *temp;
				switch(mode){
					case 1: /* PvP */ 
						updateMessage(board);
						/*board->turn++;*/
						break;
					case 2: /* P vs AI */
						if(board->turn%2 == aiTeam1){ /* AI's turn */
							printMessage(board->turn);
							if (board->turn == 0){
								temp = getCell(12, board);
								movePiece(temp->piece, getCell(20, board));
								temp = NULL;
							}
							else if (board->turn == 1){
								temp = getCell(52, board);
								movePiece(temp->piece, getCell(44, board));
							}
							else if (board->turn == 2){
								temp = getCell(3, board);
								movePiece(temp->piece, getCell(21, board));
							}
							else if (board->turn == 3){
								temp = getCell(59, board);
								movePiece(temp->piece, getCell(45, board));
							}
							else if (board->turn == 4){
								temp = getCell(5, board);
								movePiece(temp->piece, getCell(26, board));
							}
							else if (board->turn == 5){
								temp = getCell(61, board);
								movePiece(temp->piece, getCell(34, board));
							}
							else if (board->turn == 6){
								temp = getCell(21, board);
								movePiece(temp->piece, getCell(53, board));
							}
							else if (board->turn == 7){
								temp = getCell(45, board);
								movePiece(temp->piece, getCell(13, board));
							}
							else{
								aiMove(diff, aiTeam1, board);
							}
						}
						else{
							/* player's turn */
							updateMessage(board);
							/*board->turn++;*/
						}
						break;
					case 3: /* AI vs AI*/
						if(board->turn%2 == 0){ /* White's turn */
							/* aiTeam1 goes */
							printMessage(board->turn);
							aiMove(diff, aiTeam1, board);
							/*board->turn++;*/
						}
						else{ /* Black's turn */
							/* aiTeam2 goes */
							printMessage(board->turn);
							aiMove(diff, aiTeam2, board);
							/*board->turn++;*/
						}
						break;
				}
				/* Exits loop when turn is finished */
			}
			timer4 = (int) time(NULL);
			if (timer != 0 && board->turn > 1){
				printf("DEBUG: Current time: %d\n", timer4);
				printf("DEBUG: Current time: %d\n", timer2);
				printf("Time remaining for Player 1: %d seconds.\n", timer1);
				printf("Time remaining for Player 2: %d seconds.\n", timer3);
			}
		}
			
	}
	while(!in_game);
	
		
	return 0;
}
Beispiel #30
0
int32
OggEncoder::UpdateStatus(FILE* out, BMessenger* messenger) {
	PRINT(("OggEncoder::UpdateStatus(FILE*,BMessenger*)\n"));

	float prev = 0.0;
	float curr = 0.0;
	char buffer[2048];
	unsigned char c = 0;
	unsigned char prevc = 0;
	int i = 0;
	bool lineStarted = false;

	while (1) {
		if (CheckForCancel()) {
			PRINT(("Cancel requested.\n"));
			return FSS_CANCEL_ENCODING;
		}

		if (feof(out)) {
			PRINT(("ERROR IN ENCODING STREAM - EOF ENCOUNTERED\n"));
			return B_ERROR;
		}

		if (ferror(out)) {
			PRINT(("ERROR IN ENCODING STREAM\n"));
			return B_ERROR;
		}

		prevc = c;
		c = fgetc(out);

		if (c != 0 && c != 13) {
			if (c == 'E' && prevc == 13) {
				i = 0;
			} else if (c == '%') {
				buffer[i] = '\0';
				char* tmp;
				if (buffer[i-5] != ' ') {
					tmp = &(buffer[i-5]);
				} else if (buffer[i-4] != ' ') {
					tmp = &(buffer[i-4]);
				} else {
					tmp = &(buffer[i-3]);
				}
				curr = atof(tmp);
				float delta = curr - prev;
				prev = curr;
				BMessage updateMessage(B_UPDATE_STATUS_BAR);
				updateMessage.AddFloat("delta", delta);
				messenger->SendMessage(&updateMessage);
			}
			buffer[i] = c;
			i++;
		} else if (c == 13) {
			buffer[i] = 0;
			PRINT(("%s\n", buffer));
		}

		if (c == 'D' && prevc == 10) {
			break;
		}
	}
	PRINT(("DONE ENCODING\n"));
	return B_OK;
}