bool Costume::open(const QString &fileName, bool externFile) { QFileInfo info(fileName); _name = info.baseName(); _nameLabel.setText(_name); QString tmpFile; if(externFile) { QTemporaryFile tmp(sMainWindow->getTempPath() + "/costume"); if (tmp.open()) tmpFile = tmp.fileName(); } if (!tmpFile.isEmpty()) { QFileInfo tmpInfo(tmpFile); _filepath = tmpFile; _filename = tmpInfo.fileName(); QFile::copy(fileName, _filepath); sMainWindow->reindexMedia(); } else { _filepath = fileName; _filename = fileName; } _costume.load(fileName); _costumeLabel.setPixmap(QPixmap::fromImage(_costume).scaled(40, 40)); hide(); return true; }
Document* FrostEdit::addDocument(const QString& path, bool ghost) { //If path exists in the open documents, we will return the pointer from list QFileInfo tmpInfo(path); QString loadPath = path; if(tmpInfo.exists() && tmpInfo.isFile()) { loadPath = tmpInfo.absoluteFilePath(); } if(mOpenDocuments.contains(loadPath)) { Document* doc = mOpenDocuments[loadPath]; return doc; } //If file didn't exists and the path isn't file at all (and it's not ghost), we will make a MessageBox. if(!QFile::exists(loadPath)) { if(ghost == false) QMessageBox::critical(this, "ERROR!", tr("File: %1 does not exists!").arg(loadPath), "OK"); return nullptr; } //We make a new file.. Document* doc = new Document(this, loadPath); connect(doc, &Document::exterminate, this, &FrostEdit::removeDocument); mOpenDocuments.insert(path, doc); //Setting up a highlighter for it.. setUpDocumentHiltter(doc); //Set up a frostcodemodel CodeModel* model = new Frost::FrostCodeModel(mFrostModelContext); doc->setCodeModel(model); //If file isn't ghost we'll ad it into a open documents list if(ghost == false) addDocumentItem(doc); //Let's keep eye on the file, to get notifications if the file was modified outside of the editor mDocumentWatcher->addPath(path); //Let's add the file in every TabWidgetFrames' comboboxes.. for(TabWidgetFrame* tab: mTabWidgetFrames) { tab->addComboBoxItem(loadPath); } //Let's connect the textChanged signal to update tab header... connect(doc, &Document::textChanged, this, &FrostEdit::updateTabHeader); //We're done here. return doc; }
void PreviewThread::savePreview() // ---------------------------------------------------------------------------- // Save a preview of the image, and wait until awoken again // ---------------------------------------------------------------------------- { // Acquire input parameters mutex.lock(); QImage toSave = image; QString filePath = path; uint width = maxWidth; uint height = maxHeight; image = QImage(); mutex.unlock(); // Check if there is anything interesting to save if (!toSave.isNull() && filePath != "") { // Arm singles shot time for next save nextSave.start(timeInterval); // Rescale image to maximum dimensions if ((uint) toSave.width() > maxWidth) toSave = toSave.scaledToWidth(width); if ((uint) toSave.height() > maxHeight) toSave = toSave.scaledToHeight(height); // Save image in a temporary file QFileInfo fileInfo (filePath); QFileInfo tmpInfo(fileInfo.dir(), "tmp-" + fileInfo.fileName()); toSave.save(tmpInfo.filePath()); // Rename file to target (automic or near-atomic operation) QDir dir = fileInfo.dir(); dir.remove(fileInfo.fileName()); dir.rename(tmpInfo.fileName(), fileInfo.fileName()); } }