void FileEngine::performFileOperation(const QString &fileOperation, const QStringList &clipboardList, const QString &clipboardDir, const QStringList &selectedFiles, const QString &directory) { Worker *worker = new Worker(); connect(worker, SIGNAL(progressTextChanged(QString)), this, SIGNAL(progressTextChanged(QString))); connect(worker, SIGNAL(currentEntryChanged(QString)), this, SIGNAL(currentEntryChanged(QString))); connect(worker, SIGNAL(progressValueChanged(double)), this, SIGNAL(progressValueChanged(double))); connect(worker, SIGNAL(fileOperationFinished()), this, SIGNAL(fileOperationFinished())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); if (fileOperation == "paste") { bool cut = false; if (clipboard->getFileOperation() == "cut") cut = true; worker->startPasteProcess(clipboardList, directory, clipboardDir, cut); } else if (fileOperation == "delete") { worker->startDeleteProcess(selectedFiles); } }
void CoreConnection::setProgressText(const QString &text) { if (_progressText != text) { _progressText = text; emit progressTextChanged(text); } }
WebUi::WebUi(WApplication *app) : AbstractUi(), m_app(app) { app->setTitle("Quassel web interface"); WVBoxLayout *layout = new WVBoxLayout; app->root()->setLayout(layout); /*m_loginButton = new WPushButton("Connect"); m_loginButton->clicked().connect(this, &WebUi::connect); layout->addWidget(m_loginButton);*/ _chatView = new WTableView(app->root()); layout->addWidget(_chatView); _inputWidget = new WLineEdit(app->root()); layout->addWidget(_inputWidget); QObject::connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString)), SLOT(userAuthenticationRequired(CoreAccount*,bool*,QString))); QObject::connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), SLOT(printMsg(QString))); QObject::connect(Client::coreConnection(), SIGNAL(progressTextChanged(QString)), SLOT(printMsg(QString))); QObject::connect(Client::coreConnection(), SIGNAL(connectionError(QString)), SLOT(printMsg(QString))); QObject::connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(printMsg(QString))); //QObject::connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString)), SLOT(userAuthenticationRequired(CoreAccount*,bool*,QString))); //Client::coreAccountModel()->load(); //if (!Client::coreConnection()->connectToCore()) { bool ok; userAuthenticationRequired(0, &ok, ""); //} }
void FutureWatcher::customEvent(QEvent* event) { if(_futureInterface) { OVITO_ASSERT(static_cast<CallOutEvent*>(event)->_source == _futureInterface.get()); if(event->type() == (QEvent::Type)CallOutEvent::Started) Q_EMIT started(); else if(event->type() == (QEvent::Type)CallOutEvent::Finished) { _finished = true; Q_EMIT finished(); } else if(event->type() == (QEvent::Type)CallOutEvent::Canceled) Q_EMIT canceled(); else if(event->type() == (QEvent::Type)CallOutEvent::ResultReady) { if(!_futureInterface->isCanceled()) { Q_EMIT resultReady(); } } else if(event->type() == (QEvent::Type)CallOutEvent::ProgressValue) { if(!_futureInterface->isCanceled()) Q_EMIT progressValueChanged(static_cast<CallOutEvent*>(event)->_value); } else if(event->type() == (QEvent::Type)CallOutEvent::ProgressText) { if(!_futureInterface->isCanceled()) Q_EMIT progressTextChanged(static_cast<CallOutEvent*>(event)->_text); } else if(event->type() == (QEvent::Type)CallOutEvent::ProgressRange) { Q_EMIT progressRangeChanged(static_cast<CallOutEvent*>(event)->_value); } } QObject::customEvent(event); }
CoreConnectionStatusWidget::CoreConnectionStatusWidget(CoreConnection *connection, QWidget *parent) : QWidget(parent), _coreConnection(connection) { ui.setupUi(this); ui.lagLabel->hide(); ui.sslLabel->hide(); update(); connect(coreConnection(), SIGNAL(progressTextChanged(QString)), ui.messageLabel, SLOT(setText(QString))); connect(coreConnection(), SIGNAL(progressValueChanged(int)), ui.progressBar, SLOT(setValue(int))); connect(coreConnection(), SIGNAL(progressRangeChanged(int, int)), ui.progressBar, SLOT(setRange(int, int))); connect(coreConnection(), SIGNAL(progressRangeChanged(int, int)), this, SLOT(progressRangeChanged(int, int))); connect(coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), SLOT(connectionStateChanged(CoreConnection::ConnectionState))); connect(coreConnection(), SIGNAL(connectionError(QString)), ui.messageLabel, SLOT(setText(QString))); connect(coreConnection(), SIGNAL(lagUpdated(int)), SLOT(updateLag(int))); }
/*! \fn FutureProgress::FutureProgress(QWidget *parent) \internal */ FutureProgress::FutureProgress(QWidget *parent) : QWidget(parent), d(new FutureProgressPrivate(this)) { QVBoxLayout *layout = new QVBoxLayout; setLayout(layout); layout->addWidget(d->m_progress); layout->setMargin(0); layout->setSpacing(0); layout->addLayout(d->m_widgetLayout); d->m_widgetLayout->setContentsMargins(7, 0, 7, 2); d->m_widgetLayout->setSpacing(0); connect(&d->m_watcher, SIGNAL(started()), this, SLOT(setStarted())); connect(&d->m_watcher, SIGNAL(finished()), this, SLOT(setFinished())); connect(&d->m_watcher, SIGNAL(canceled()), this, SIGNAL(canceled())); connect(&d->m_watcher, SIGNAL(progressRangeChanged(int,int)), this, SLOT(setProgressRange(int,int))); connect(&d->m_watcher, SIGNAL(progressValueChanged(int)), this, SLOT(setProgressValue(int))); connect(&d->m_watcher, SIGNAL(progressTextChanged(QString)), this, SLOT(setProgressText(QString))); connect(d->m_progress, SIGNAL(clicked()), this, SLOT(cancel())); }
TFutureProgress::TFutureProgress(QWidget *Parent): QWidget(Parent), d_ptr(new TFutureProgressPrivate) { Q_D(TFutureProgress); d->q_ptr = this; d->FaderWidget = new TFadeWidgetHack(this); QVBoxLayout *Layout = new QVBoxLayout; Layout->setMargin(0); Layout->setSpacing(0); Layout->addWidget(d->Progress); Layout->addLayout(d->WidgetLayout); d->WidgetLayout->setContentsMargins(2, 1, 2, 1); d->WidgetLayout->setSpacing(0); setLayout(Layout); connect(&d->Watcher, SIGNAL(started()), this, SLOT(_q_SetStarted())); connect(&d->Watcher, SIGNAL(finished()), this, SLOT(_q_SetFinished())); connect(&d->Watcher, SIGNAL(canceled()), this, SIGNAL(Canceled())); connect(&d->Watcher, SIGNAL(progressRangeChanged(int,int)), this, SLOT(_q_SetProgressRange(int,int))); connect(&d->Watcher, SIGNAL(progressValueChanged(int)), this, SLOT(_q_SetProgressValue(int))); connect(&d->Watcher, SIGNAL(progressTextChanged(QString)), this, SLOT(_q_SetProgressText(QString))); connect(d->Progress, SIGNAL(Clicked()), this, SLOT(_q_Cancel())); }
/* * Paste files to destination */ void Worker::pasteFiles(bool cut) { buildFileList(); QList<QString> directoryList; QDir sourceDir(m_clipboardDir); QTime startTime = QTime::currentTime(); emit progressTextChanged(QString("Copying files...")); // Create a list of directories to be created for (int i=0; i < m_directoryList.count(); i++) { QString sourcePath = m_directoryList.at(i); QString newDirPath = QString("%1/%2").arg(m_destination, sourceDir.relativeFilePath(sourcePath)); qDebug() << sourcePath.toLatin1() << " > " << newDirPath.toLatin1(); directoryList.append(newDirPath); } emit progressTextChanged("Creating directories..."); qDebug() << "FILES"; // Create a list of files to be copied for (int i=0; i < m_fileList.count(); i++) { QString sourcePath = m_fileList.at(i); QString newFilePath = QString("%1/%2").arg(m_destination, sourceDir.relativeFilePath(sourcePath)); qDebug() << sourcePath.toLatin1() << " > " << newFilePath.toLatin1(); m_fileMap.insert(sourcePath, newFilePath); } // First, create the directories for (int i = 0; i < directoryList.count(); i++) { QString newDir = directoryList.at(i); QDir dir(newDir); // If the directory already exists, skip it if (dir.exists()) continue; bool success = dir.mkdir(newDir); if (!success) directoryErrorMap.insert(newDir, DirCreateError); } // If any of the directories couldn't be created, abort the process if (directoryErrorMap.count() > 0) { emit progressTextChanged("Directories couldn't be created."); emit fileOperationFinished(); // Abort the process quit(); } // Now, copy the files int fileCount = 0; QMapIterator<QString, QString> i(m_fileMap); while (i.hasNext()) { i.next(); fileCount++; QString sourceFilePath = i.key(); QString newFilePath = i.value(); QFile sourceFile(sourceFilePath); // Report the progress, but only every 50 milliseconds to prevent the UI thread // from being flooded with signals if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Copying files (%1 of %2)...").arg(QString("%1").arg(fileCount), QString("%1").arg(m_fileMap.count()))); emit currentEntryChanged(sourceFile.fileName()); double progress = (double)(fileCount) / (double)m_fileMap.count(); emit progressValueChanged(progress); } // Copy the file bool success = sourceFile.copy(sourceFilePath, newFilePath); if (!success) fileErrorMap.insert(newFilePath, sourceFile.error()); } // If we don't have to cut files we are done if (!cut) { if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) emit progressTextChanged("All files were copied successfully."); else emit progressTextChanged("All files couldn't be copied successfully."); emit fileOperationFinished(); // Done, time to self-destruct quit(); } else { fileCount = 0; if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) { // We copied all files successfully, so delete the old ones now i.toFront(); while (i.hasNext()) { i.next(); fileCount++; QString sourceFilePath = i.key(); QFile sourceFile(sourceFilePath); // Report the progress, but only every 50 milliseconds to prevent the UI thread // from being flooded with signals if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Deleting old files (%1 of %2)...").arg(QString("%1").arg(fileCount), QString("%1").arg(m_fileMap.count()))); emit currentEntryChanged(sourceFile.fileName()); double progress = (double)(fileCount) / (double)m_fileMap.count(); emit progressValueChanged(progress); } // Delete the file bool success = sourceFile.remove(); if (!success) fileErrorMap.insert(sourceFilePath, sourceFile.error()); } emit progressTextChanged(QString("Deleting old directories...")); emit progressValueChanged(-1); // Then delete the directories for (int i=m_directoryList.count()-1; i >= 0; i--) { QString sourcePath = m_directoryList.at(i); QDir dir(sourcePath); // If it doesn't exist, it was most likely removed earlier if (!dir.exists()) continue; bool success = dir.rmdir(sourcePath); if (!success) directoryErrorMap.insert(sourcePath, DirDeleteError); } // Check if files were copied and deleted successfully if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) emit progressTextChanged("All of the files were cut and pasted successfully."); else emit progressTextChanged("All of the files couldn't be cut and pasted successfully."); emit fileOperationFinished(); // Done, time to self-destruct quit(); } else { // All files couldn't be copied, so delete the new copied files to revert the process i.toFront(); while (i.hasNext()) { i.next(); fileCount++; QString newFilePath = i.value(); QFile newFile(newFilePath); // Report the progress, but only every 50 milliseconds to prevent the UI thread // from being flooded with signals if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Failed to copy all files, deleting copied files (%1 of %2)...").arg(QString("%1").arg(fileCount), QString("%1").arg(m_fileMap.count()))); emit currentEntryChanged(newFile.fileName()); double progress = (double)(fileCount) / (double)m_fileMap.count(); emit progressValueChanged(progress); } // Delete the file newFile.remove(); } emit progressTextChanged(QString("Failed to copy all files, deleting created directories...")); emit progressValueChanged(-1); // Delete the directories for (int i=directoryList.count()-1; i >= 0; i--) { QString newDir = directoryList.at(i); QDir dir(newDir); // If the directory already exists, skip it if (dir.exists()) continue; bool success = dir.rmdir(newDir); if (!success) directoryErrorMap.insert(newDir, DirDeleteError); } emit progressTextChanged("All files couldn't be copied successfully."); emit fileOperationFinished(); } } }
/* * Delete files in the clipboard */ void Worker::deleteFiles() { buildFileList(); emit progressTextChanged(QString("Deleting files...")); QTime startTime = QTime::currentTime(); // Start deleting files for (int i=0; i < m_fileList.count(); i++) { QString fullPath = m_fileList.at(i); QFile file(fullPath); // Report the progress if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Deleting files (%1 of %2)...").arg(QString("%1").arg(i+1), QString("%1").arg(m_fileList.count()))); emit currentEntryChanged(file.fileName()); double progress = (double)(i + 1) / (double)m_fileList.count(); emit progressValueChanged(progress); } file.open(QIODevice::WriteOnly); // Remove the file bool success = file.remove(); if (!success) fileErrorMap.insert(fullPath, file.error()); } // And then delete directories // Reverse order so that the subdirectories are deleted first for (int i=m_directoryList.count()-1; i >= 0; i--) { QString fullPath = m_directoryList.at(i); QDir dir(fullPath); // If it doesn't exist, it was most likely removed earlier if (!dir.exists()) continue; bool success = dir.rmdir(fullPath); if (!success) directoryErrorMap.insert(fullPath, DirDeleteError); if (QTime::currentTime().msecsTo(startTime) <= -50) { startTime = QTime::currentTime(); emit progressTextChanged(QString("Deleting directories...")); emit currentEntryChanged(dir.dirName()); emit progressValueChanged(-1); } } // We are done if (fileErrorMap.count() == 0 && directoryErrorMap.count() == 0) emit progressTextChanged("All files were deleted successfully."); else emit progressTextChanged("All files couldn't be deleted successfully."); emit fileOperationFinished(); // Done, time to self-destruct quit(); }