void QxFileBrowser::fileRenamed(const QString& path, const QString& oldName, const QString& newName ) { if (QFileInfo(QDir(path).filePath(oldName)).isDir()) emit dirRenamed(QDir(path).filePath(oldName), QDir(path).filePath(newName)); else emit fileRenamed(QDir(path).filePath(oldName), QDir(path).filePath(newName)); }
bool ScanGallery::slotFileRenamed(FileTreeViewItem *item, const QString &newName) { if (item->isRoot()) return (false); // cannot rename root here KUrl urlFrom = item->url(); kDebug() << "url" << urlFrom << "->" << newName; QString oldName = urlFrom.fileName(); KUrl urlTo(urlFrom); urlTo.setFileName(newName); /* clear selection, because the renamed image comes in through * kdirlister again */ // slotUnloadItem(item); // unnecessary, bug 68532 // because of "note new URL" below kDebug() << "Renaming " << urlFrom << "->" << urlTo; //setSelected(item,false); bool success = ImgSaver::renameImage(urlFrom, urlTo, true, this); if (success) // rename the file { item->setUrl(urlTo); // note new URL emit fileRenamed(item->fileItem(), newName); } else { kDebug() << "renaming failed"; item->setText(0, oldName); // restore original name } // setSelected(item,true); // restore the selection return (success); }
void FileBrowser::createConnections() { connect(renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile())); connect(removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile())); connect(fileModel, SIGNAL(fileRenamed(QString, QString, QString)), this, SLOT(fileRenameDone())); auto stopEditingSlot = [&]() { fileModel->setReadOnly(true); }; connect(fileView, &QTreeView::doubleClicked, stopEditingSlot); connect(openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); connect(zipFilesAction, SIGNAL(triggered()), this, SLOT(zipFiles())); connect(dirView, SIGNAL(clicked(QModelIndex)), this, SLOT(showFiles(QModelIndex))); }
////////////////////////////////////////////////////////////////////////// /// Add a FileSystemWatcher to the directory /// /// Creates a FileSystemWatcher, connects all the signals, adds it to the /// list of watchers and starts it. ////////////////////////////////////////////////////////////////////////// void SyncSystem::slotStartNodeWatching(const QString& dir) { QString watchDir = joinPath(m_CurrentSourcePath, dir); qDebug() << "[SyncSystem.Debug] slotStartNodeWatching in dir " << watchDir; FileSystemWatcher* watcher = new FileSystemWatcher(); connect(watcher, SIGNAL(fileAdded(QString)), SLOT(slotFileAdded(QString))); connect(watcher, SIGNAL(fileDeleted(QString)), SLOT(slotFileDeleted(QString))); connect(watcher, SIGNAL(fileChanged(QString)), SLOT(slotFileChanged(QString))); connect(watcher, SIGNAL(fileRenamed(QString,QString)), SLOT(slotFileRenamed(QString,QString))); connect(watcher, SIGNAL(filewatchError(QString)), SLOT(slotFilewatchError(QString))); connect(watcher, SIGNAL(filewatchLostSync(QString)), SLOT(slotLostSync())); m_FileSystemWatchers.append(watcher); watcher->setWatchDir(watchDir); watcher->setRelativeDir(dir); watcher->start(); }
bool Project::setData(const QModelIndex& index, const QVariant& value, int role) { editable = QModelIndex(); QString oldName = itemFromIndex(index)->text(); if (oldName==value.toString()) return false; QString filePath = QFileInfo(fileAtIndex(index)).canonicalPath(); bool success = QFile::rename(filePath+"/"+oldName,filePath+"/"+value.toString()); if (success) { _files[filePath+"/"+value.toString()] = _files[filePath+"/"+oldName]; _files.remove(filePath+"/"+oldName); setModified(true, true); emit fileRenamed(filePath+"/"+oldName,filePath+"/"+value.toString()); return QStandardItemModel::setData(index,value,role); } else { return false; } }
FileManager::Status FileManager::rename(const QString &pOldFileName, const QString &pNewFileName) { // Check whether the 'old' file is managed QString oldFileName = nativeCanonicalFileName(pOldFileName); QString newFileName = nativeCanonicalFileName(pNewFileName); File *file = isManaged(oldFileName); if (!file) { // The 'old' file is not managed, so... return NotManaged; } else { // The 'old' file is managed, so we can rename it file->setFileName(newFileName); emit fileRenamed(oldFileName, newFileName); return Renamed; } }
GitBrowser::GitBrowser(QString localRepoFolder, QWidget *parent) : QWidget(parent), newDocumentDialog(0) { Q_INIT_RESOURCE(gitbrowser); ui = new Ui::GitBrowser; ui->setupUi(this); repoParams = new RepoParams(); model = new QFileSystemModel; model->setNameFilters(QStringList()<<"*.lyx"); model->setNameFilterDisables(false); repoFolder = localRepoFolder; model->setRootPath(repoFolder); model->setReadOnly(false); ui->listView->setModel(model); ui->listView->setEditTriggers(QAbstractItemView::SelectedClicked|QAbstractItemView::EditKeyPressed); connect(model, SIGNAL(fileRenamed(QString,QString,QString)), this, SLOT(onFileRenamed(QString,QString,QString))); syncWidget = new SyncDialog(this); repoSettingsDialog = new RepoSettings(this); connect(repoSettingsDialog, SIGNAL(changed()), this, SLOT(updateRepoParams())); git = new GitManager(repoFolder); actUpdate = new QAction(QIcon(":/images/refresh.png"), "Обновить", this); connect(actUpdate, SIGNAL(triggered()), this, SLOT(callUpdate())); actUp = new QAction(QIcon(":/images/arrow-up.png"), "Перейти на каталог выше", this); connect(actUp, SIGNAL(triggered()), this, SLOT(up())); actGo = new QAction(QIcon(":/images/go.png"), "Перейти", this); connect(actGo, SIGNAL(triggered()), this, SLOT(onGoBtn_clicked())); actOpen = new QAction("Открыть", this); connect(actOpen, SIGNAL(triggered()), this, SLOT(callOpen())); actVersions = new QAction("Версии...", this); connect(actVersions, SIGNAL(triggered()), this, SLOT(callVersions())); actRename = new QAction("Переименовать", this); connect(actRename, SIGNAL(triggered()), this, SLOT(callRename())); actRemove = new QAction("Удалить", this); connect(actRemove, SIGNAL(triggered()), this, SLOT(callRemove())); actNewDir = new QAction("Новая папка", this); connect(actNewDir, SIGNAL(triggered()), this, SLOT(callNewDir())); actNewDocument = new QAction(QIcon(":/images/new-document.png"), "Новый документ", this); connect(actNewDocument, SIGNAL(triggered()), this, SLOT(callNewDocument())); actCopy = new QAction("Копировать", this); connect(actCopy, SIGNAL(triggered()), this, SLOT(callCopy())); actCut = new QAction("Вырезать", this); connect(actCut, SIGNAL(triggered()), this, SLOT(callCut())); actPaste = new QAction("Вставить", this); connect(actPaste, SIGNAL(triggered()), this, SLOT(callPaste())); actRepoSettings = new QAction(QIcon(":/images/settings.png"), "Настройки репозитория", this); connect(actRepoSettings, SIGNAL(triggered(bool)), SLOT(callRepoSettings())); ui->listView->setContextMenuPolicy(Qt::CustomContextMenu); registerAction("settings", actRepoSettings); registerAction("new-document", actNewDocument); ui->navigationPanel->addActions(QList<QAction* >()<<actUpdate<<actUp); pathLE = new QLineEdit(); connect(pathLE, SIGNAL(returnPressed()), this, SLOT(onLineEdit_returnPressed())); ui->navigationPanel->addWidget(pathLE); ui->navigationPanel->addActions(QList<QAction* >()<<actGo); QList<int> list= ui->splitter->sizes(); list.replace(0,200); list.replace(1,this->width()-200); ui->splitter->setSizes(list); QJS rootItem; rootItem["name"] = "Хранилища"; QJS n1; n1["name"] = "Отчеты"; n1["type"] = "folder"; QJS n2; n2["name"] = "Карточки"; n2["type"] = "folder"; QJS n3; n3["name"] = "Инструкции"; n3["type"] = "folder"; QJS n4; n4["name"] = "Генетические отчеты"; n4["type"] = "folder"; QJS n5; n5["name"] = "Прочие отчеты"; n5["type"] = "folder"; n1["children"][0] = n4; n1["children"][1] = n5; rootItem["children"][0] = n1; rootItem["children"][1] = n2; rootItem["children"][2] = n3; QJSModel *rm = new QJSModel(rootItem); rm->setIcon("folder", "://images/folder.png"); ui->treeView->setModel(rm); go("/"); connect(syncWidget, SIGNAL(retry()), this, SLOT(retry())); }
bool QuaMainWindow::QuaSaveAsDocument() { QString tFileName; if ( mQuaTextEdit->document()->isModified() ) { mQuaTextEdit->IBFSaveToFile(mQuaTextEdit->windowFilePath()); } tFileName = QFileDialog::getSaveFileName(this, tr("Save as..."), QString(), tr("ZIP-Files (*.zip);;All Files (*)")); if ( tFileName.isEmpty() ) { return false; } if (! (tFileName.endsWith(".zip", Qt::CaseInsensitive) ) ) { tFileName += ".zip"; } if ( !JlCompress::compressDir(tFileName, mIBFTemporaryDir->path())) { QMessageBox::critical(NULL, "Critical Error", "Something went wrong with JlCompress::compressDir(tFileName, mTemporaryDir->path())...", QMessageBox::Ok); return false; } if ( !QFile::exists(tFileName) ) { QMessageBox::critical(NULL, "Critical Error", "Something went wrong with QFile::exists(tFileName)...", QMessageBox::Ok); return false; } // // Open Saved Document // if ( tFileName.isEmpty() ) { return false; } if ( !QFile::exists(tFileName) ) { return false; } if ( !this->QuaCloseDocument() ) { QMessageBox::critical(NULL, "Critical Error", "Something went wrong with this->QuaCloseDocument()...", QMessageBox::Ok); return false; } mIBFDocument = new QFile(tFileName); if ( !mIBFDocument->open(QFile::ReadOnly) ) { return false; } mIBFTemporaryDir = new QTemporaryDir(); if ( !mIBFTemporaryDir->isValid() ) { return false; } if ( JlCompress::extractDir(tFileName, mIBFTemporaryDir->path()).isEmpty() ) { QMessageBox::critical(NULL, "Critical Error", "Something went wrong with JlCompress::extractDir(aString, mTemporaryDir->path()).isEmpty()...", QMessageBox::Ok); return false; } mIBFFileSystemModel = new QFileSystemModel(); mIBFFileSystemModel->setRootPath(mIBFTemporaryDir->path()); mIBFFileSystemModel->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); mIBFFileSystemModel->setReadOnly(false); mIBFTreeView->setModel(mIBFFileSystemModel); mIBFTreeView->setRootIndex(mIBFFileSystemModel->index(mIBFTemporaryDir->path())); mIBFTreeView->setHeaderHidden(true); mIBFTreeView->setColumnHidden(1, true); mIBFTreeView->setColumnHidden(2, true); mIBFTreeView->setColumnHidden(3, true); mIBFTreeView->setWordWrap(true); QObject::connect(mIBFTreeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(on_mIBFTreeView_selectionChanged_triggered(const QModelIndex &, const QModelIndex &))); QObject::connect(mIBFFileSystemModel, SIGNAL(fileRenamed(QString,QString,QString)), this, SLOT(on_mIBFFileSystemModelDirs_fileRenamed_triggered(QString,QString,QString))); mIBFTreeView->setEnabled(true); mIBFTreeView->setFocus(); this->setWindowModified(false); this->setWindowFilePath(tFileName); this->IBFUpdateTitle(); return true; }