PreviewSelect::PreviewSelect(QWidget* parent, BitTorrent::TorrentHandle *const torrent) : QDialog(parent) , m_torrent(torrent) { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); Preferences* const pref = Preferences::instance(); // Preview list previewListModel = new QStandardItemModel(0, NB_COLUMNS); previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name")); previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); // This hack fixes reordering of first column with Qt5. // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777 QTableView unused; unused.setVerticalHeader(previewList->header()); previewList->header()->setParent(previewList); unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); previewList->setModel(previewListModel); previewList->hideColumn(FILE_INDEX); listDelegate = new PreviewListDelegate(this); previewList->setItemDelegate(listDelegate); previewList->header()->resizeSection(0, 200); previewList->setAlternatingRowColors(pref->useAlternatingRowColors()); // Fill list in QVector<qreal> fp = torrent->filesProgress(); int nbFiles = torrent->filesCount(); for (int i = 0; i < nbFiles; ++i) { QString fileName = torrent->fileName(i); if (fileName.endsWith(QB_EXT)) fileName.chop(4); QString extension = Utils::Fs::fileExtension(fileName).toUpper(); if (Utils::Misc::isPreviewable(extension)) { int row = previewListModel->rowCount(); previewListModel->insertRow(row); previewListModel->setData(previewListModel->index(row, NAME), QVariant(fileName)); previewListModel->setData(previewListModel->index(row, SIZE), QVariant(torrent->fileSize(i))); previewListModel->setData(previewListModel->index(row, PROGRESS), QVariant(fp[i])); previewListModel->setData(previewListModel->index(row, FILE_INDEX), QVariant(i)); } } if (!previewListModel->rowCount()) { QMessageBox::critical(this->parentWidget(), tr("Preview impossible"), tr("Sorry, we can't preview this file")); close(); } connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString))); previewListModel->sort(NAME); previewList->header()->setSortIndicator(0, Qt::AscendingOrder); previewList->selectionModel()->select(previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows); if (previewListModel->rowCount() == 1) { qDebug("Torrent file only contains one file, no need to display selection dialog before preview"); // Only one file : no choice on_previewButton_clicked(); }else{ qDebug("Displaying media file selection dialog for preview"); show(); } }
void KNThemeManager::loadThemeFiles(const QString &themeDirPath) { //Clear the previous theme list. m_themeList.clear(); //Add the default theme as the first item in the list. addTheme("Default", "://configure/default.json", QPixmap()); //The structure of a theme directory. /* Theme * |-<Theme Name> * | |-<Theme Name>.json * | |-<Theme Name>.png */ //Check the folder exist. If no, return. QDir themeFolder(themeDirPath); if(!themeFolder.exists()) { return; } //Get all the folder in the theme folder. QFileInfoList folderList=themeFolder.entryInfoList(); for(QFileInfoList::const_iterator i=folderList.constBegin(); i!=folderList.constEnd(); ++i) { QString themeName=(*i).fileName(); //Ignore if the current info is not folder, dot(.) and dot-dot(..). if(!(*i).isDir() || themeName=="." || themeName=="..") { continue; } //Get the theme file and the preview image. QFileInfo themeFile((*i).absoluteFilePath()+"/"+themeName+".json"), previewFile((*i).absoluteFilePath()+"/"+themeName+".png"); if(themeFile.exists()) { //Check the preview image. QPixmap previewImage; if(previewFile.exists()) { previewImage.load(previewFile.absoluteFilePath()); if(previewImage.isNull()) { //! FIXME: Set the preview to no image. ; } } else { //! FIXME: Set the preview to no image. ; } //Add the new theme addTheme(themeName, themeFile.absoluteFilePath(), previewImage); } } }
wxString reProjectAssets::GetAssetIconPath(rAssetType assetType, const wxString& name) { wxFileName previewFile(m_assetsDir); previewFile.AppendDir("icons"); previewFile.SetName("model_" + name); previewFile.SetExt("png"); return previewFile.GetFullPath(); }
void FileTransferInstance::onFileTransferFinished(ToxFile File) { if (File.fileNum != fileNum || File.friendId != friendId || File.direction != direction) return; disconnect(Core::getInstance(),0,this,0); if (File.direction == ToxFile::RECEIVING) { QImage preview; QFile previewFile(File.filePath); if (previewFile.open(QIODevice::ReadOnly) && previewFile.size() <= MAX_PREVIEW_SIZE) // Don't preview big (>25MiB) images { if (preview.loadFromData(previewFile.readAll())) { pic = preview.scaledToHeight(50); } previewFile.close(); } } state = tsFinished; emit stateUpdated(); }
bool BasketThumbCreator::create(const QString &path, int /*width*/, int /*height*/, QImage &image) { // Create the temporar folder: KTempDir tempDir; tempDir.setAutoRemove(true); QString tempFolder = tempDir.name(); QDir dir; dir.mkdir(tempFolder); const unsigned long int BUFFER_SIZE = 1024; QFile file(path); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); stream.setCodec(QTextCodec::codecForName("UTF-8")); QString line = stream.readLine(); if (line != "BasKetNP:archive" && line != "BasKetNP:template") { file.close(); return false; } while (!stream.atEnd()) { // Get Key/Value Pair From the Line to Read: line = stream.readLine(); int index = line.indexOf(':'); QString key; QString value; if (index >= 0) { key = line.left(index); value = line.right(line.length() - index - 1); } else { key = line; value = ""; } if (key == "preview*") { bool ok; ulong size = value.toULong(&ok); if (!ok) { file.close(); return false; } // Get the preview file: QFile previewFile(tempFolder + "preview.png"); if (previewFile.open(QIODevice::WriteOnly)) { char *buffer = new char[BUFFER_SIZE]; long int sizeRead; while ((sizeRead = file.read(buffer, qMin(BUFFER_SIZE, size))) > 0) { previewFile.write(buffer, sizeRead); size -= sizeRead; } previewFile.close(); delete buffer; image = QImage(tempFolder + "preview.png"); file.close(); return true; } } else if (key.endsWith("*")) { // We do not know what it is, but we should read the embedded-file in order to discard it: bool ok; ulong size = value.toULong(&ok); if (!ok) { file.close(); return false; } // Get the archive file: char *buffer = new char[BUFFER_SIZE]; long int sizeRead; while ((sizeRead = file.read(buffer, qMin(BUFFER_SIZE, size))) > 0) { size -= sizeRead; } delete buffer; } } file.close(); } return false; }
void WaveMaker::createGUI(DefaultGUIModel::variable_t *var, int size) { QBoxLayout *layout = new QHBoxLayout(this); // overall GUI layout // Left side GUI QBoxLayout *leftlayout = new QVBoxLayout(); QHButtonGroup *fileBox = new QHButtonGroup("File:", this); QPushButton *loadBttn = new QPushButton("Load File", fileBox); QPushButton *previewBttn = new QPushButton("Preview File", fileBox); QObject::connect(loadBttn, SIGNAL(clicked()), this, SLOT(loadFile())); QObject::connect(previewBttn, SIGNAL(clicked()), this, SLOT(previewFile())); QHBox *utilityBox = new QHBox(this); pauseButton = new QPushButton("Pause", utilityBox); pauseButton->setToggleButton(true); QObject::connect(pauseButton, SIGNAL(toggled(bool)), this, SLOT(pause(bool))); QObject::connect(pauseButton, SIGNAL(toggled(bool)), loadBttn, SLOT(setEnabled(bool))); QPushButton *modifyButton = new QPushButton("Modify", utilityBox); QObject::connect(modifyButton, SIGNAL(clicked(void)), this, SLOT(modify(void))); QPushButton *unloadButton = new QPushButton("Unload", utilityBox); QObject::connect(unloadButton, SIGNAL(clicked(void)), this, SLOT(exit(void))); QObject::connect(pauseButton, SIGNAL(toggled(bool)), modifyButton, SLOT(setEnabled(bool))); QToolTip::add(pauseButton, "Start/Stop Plug-in"); QToolTip::add(modifyButton, "Commit Changes to Parameter Values"); QToolTip::add(unloadButton, "Close Plug-in"); // Add custom left side GUI components to layout above default_gui_model components leftlayout->addWidget(fileBox); QScrollView *sv = new QScrollView(this); sv->setResizePolicy(QScrollView::AutoOneFit); leftlayout->addWidget(sv); QWidget *viewport = new QWidget(sv->viewport()); sv->addChild(viewport); QGridLayout *scrollLayout = new QGridLayout(viewport, 1, 2); size_t nstate = 0, nparam = 0, nevent = 0, ncomment = 0; for (size_t i = 0; i < num_vars; i++) { if (vars[i].flags & (PARAMETER | STATE | EVENT | COMMENT)) { param_t param; param.label = new QLabel(vars[i].name, viewport); scrollLayout->addWidget(param.label, parameter.size(), 0); param.edit = new DefaultGUILineEdit(viewport); scrollLayout->addWidget(param.edit, parameter.size(), 1); QToolTip::add(param.label, vars[i].description); QToolTip::add(param.edit, vars[i].description); if (vars[i].flags & PARAMETER) { if (vars[i].flags & DOUBLE) { param.edit->setValidator(new QDoubleValidator(param.edit)); param.type = PARAMETER | DOUBLE; } else if (vars[i].flags & UINTEGER) { QIntValidator *validator = new QIntValidator(param.edit); param.edit->setValidator(validator); validator->setBottom(0); param.type = PARAMETER | UINTEGER; } else if (vars[i].flags & INTEGER) { param.edit->setValidator(new QIntValidator(param.edit)); param.type = PARAMETER | INTEGER; } else param.type = PARAMETER; param.index = nparam++; param.str_value = new QString; } else if (vars[i].flags & STATE) { param.edit->setReadOnly(true); param.edit->setPaletteForegroundColor(Qt::darkGray); param.type = STATE; param.index = nstate++; } else if (vars[i].flags & EVENT) { param.edit->setReadOnly(true); param.type = EVENT; param.index = nevent++; } else if (vars[i].flags & COMMENT) { param.type = COMMENT; param.index = ncomment++; } parameter[vars[i].name] = param; } } // add custom components to layout below default_gui_model components leftlayout->addWidget(utilityBox); // Add left and right side layouts to the overall layout layout->addLayout(leftlayout); // layout->setResizeMode(QLayout::Fixed); // set GUI refresh rate QTimer *timer = new QTimer(this); timer->start(1000); QObject::connect(timer, SIGNAL(timeout(void)), this, SLOT(refresh(void))); show(); }
void Archive::save(Basket *basket, bool withSubBaskets, const QString &destination) { QDir dir; KProgressDialog dialog(0, i18n("Save as Basket Archive"), i18n("Saving as basket archive. Please wait..."), /*Not modal, for password dialogs!*/false); dialog.showCancelButton(false); dialog.setAutoClose(true); dialog.show(); QProgressBar *progress = dialog.progressBar(); progress->setRange(0,/*Preparation:*/1 + /*Finishing:*/1 + /*Basket:*/1 + /*SubBaskets:*/(withSubBaskets ? Global::bnpView->basketCount(Global::bnpView->listViewItemForBasket(basket)) : 0)); progress->setValue(0); // Create the temporary folder: QString tempFolder = Global::savesFolder() + "temp-archive/"; dir.mkdir(tempFolder); // Create the temporary archive file: QString tempDestination = tempFolder + "temp-archive.tar.gz"; KTar tar(tempDestination, "application/x-gzip"); tar.open(QIODevice::WriteOnly); tar.writeDir("baskets", "", ""); progress->setValue(progress->value()+1); // Preparation finished kDebug() << "Preparation finished out of " << progress->maximum(); // Copy the baskets data into the archive: QStringList backgrounds; Archive::saveBasketToArchive(basket, withSubBaskets, &tar, backgrounds, tempFolder, progress); // Create a Small baskets.xml Document: QDomDocument document("basketTree"); QDomElement root = document.createElement("basketTree"); document.appendChild(root); Global::bnpView->saveSubHierarchy(Global::bnpView->listViewItemForBasket(basket), document, root, withSubBaskets); Basket::safelySaveToFile(tempFolder + "baskets.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + document.toString()); tar.addLocalFile(tempFolder + "baskets.xml", "baskets/baskets.xml"); dir.remove(tempFolder + "baskets.xml"); // Save a Small tags.xml Document: QList<Tag*> tags; listUsedTags(basket, withSubBaskets, tags); Tag::saveTagsTo(tags, tempFolder + "tags.xml"); tar.addLocalFile(tempFolder + "tags.xml", "tags.xml"); dir.remove(tempFolder + "tags.xml"); // Save Tag Emblems (in case they are loaded on a computer that do not have those icons): QString tempIconFile = tempFolder + "icon.png"; for (Tag::List::iterator it = tags.begin(); it != tags.end(); ++it) { State::List states = (*it)->states(); for (State::List::iterator it2 = states.begin(); it2 != states.end(); ++it2) { State *state = (*it2); QPixmap icon = KIconLoader::global()->loadIcon( state->emblem(), KIconLoader::Small, 16, KIconLoader::DefaultState, QStringList(), 0L, true ); if (!icon.isNull()) { icon.save(tempIconFile, "PNG"); QString iconFileName = state->emblem().replace('/', '_'); tar.addLocalFile(tempIconFile, "tag-emblems/" + iconFileName); } } } dir.remove(tempIconFile); // Finish Tar.Gz Exportation: tar.close(); // Computing the File Preview: Basket *previewBasket = basket; // FIXME: Use the first non-empty basket! QPixmap previewPixmap(previewBasket->visibleWidth(), previewBasket->visibleHeight()); QPainter painter(&previewPixmap); // Save old state, and make the look clean ("smile, you are filmed!"): NoteSelection *selection = previewBasket->selectedNotes(); previewBasket->unselectAll(); Note *focusedNote = previewBasket->focusedNote(); previewBasket->setFocusedNote(0); previewBasket->doHoverEffects(0, Note::None); // Take the screenshot: previewBasket->drawContents(&painter, 0, 0, previewPixmap.width(), previewPixmap.height()); // Go back to the old look: previewBasket->selectSelection(selection); previewBasket->setFocusedNote(focusedNote); previewBasket->doHoverEffects(); // End and save our splandid painting: painter.end(); QImage previewImage = previewPixmap.toImage(); const int PREVIEW_SIZE = 256; previewImage = previewImage.scaled(PREVIEW_SIZE, PREVIEW_SIZE, Qt::KeepAspectRatio); previewImage.save(tempFolder + "preview.png", "PNG"); // Finaly Save to the Real Destination file: QFile file(destination); if (file.open(QIODevice::WriteOnly)) { ulong previewSize = QFile(tempFolder + "preview.png").size(); ulong archiveSize = QFile(tempDestination).size(); QTextStream stream(&file); stream.setCodec("ISO-8859-1"); stream << "BasKetNP:archive\n" << "version:0.6.1\n" // << "read-compatible:0.6.1\n" // << "write-compatible:0.6.1\n" << "preview*:" << previewSize << "\n"; stream.flush(); // Copy the Preview File: const unsigned long BUFFER_SIZE = 1024; char *buffer = new char[BUFFER_SIZE]; long sizeRead; QFile previewFile(tempFolder + "preview.png"); if (previewFile.open(QIODevice::ReadOnly)) { while ((sizeRead = previewFile.read(buffer, BUFFER_SIZE)) > 0) file.write(buffer, sizeRead); } stream << "archive*:" << archiveSize << "\n"; stream.flush(); // Copy the Archive File: QFile archiveFile(tempDestination); if (archiveFile.open(QIODevice::ReadOnly)) { while ((sizeRead = archiveFile.read(buffer, BUFFER_SIZE)) > 0) file.write(buffer, sizeRead); } // Clean Up: delete buffer; buffer = 0; file.close(); } progress->setValue(progress->value()+1); // Finishing finished kDebug() << "Finishing finished"; // Clean Up Everything: dir.remove(tempFolder + "preview.png"); dir.remove(tempDestination); dir.rmdir(tempFolder); }