void FilePropertyWidgetQt::dropEvent(QDropEvent* drop) { auto data = drop->mimeData(); if (data->hasUrls()) { if(data->urls().size()>0) { auto url = data->urls().first(); property_->set(url.toLocalFile().toStdString()); drop->accept(); } } }
// Independent function that takes a url from the list as a string // Adds it to a file that contains a list of all parsed webpages void urls_parsed(std::string x){ std::ofstream urls("urls.txt", std::ios::app|std::ios::out); urls << x << std::endl; urls.close(); }
void CoverWidget::dropEvent(QDropEvent *e) { auto mimeData = e->mimeData(); QImage img; if (mimeData->hasImage()) { img = qvariant_cast<QImage>(mimeData->imageData()); } else { auto urls = mimeData->urls(); if (urls.size() == 1) { auto &url = urls.at(0); if (url.isLocalFile()) { img = App::readImage(Platform::File::UrlToLocal(url)); } } } if (!_dropArea->hiding()) { _dropArea->hideAnimated([this](Profile::CoverDropArea *area) { dropAreaHidden(area); }); } e->acceptProposedAction(); showSetPhotoBox(img); App::wnd()->activateWindow(); }
void CoverFetchArtPayload::prepareUrls() { if( m_src == CoverFetch::Google ) { // google is special prepareGoogleUrls(); return; } QXmlStreamReader xml( m_xml ); switch( m_src ) { default: case CoverFetch::LastFm: prepareLastFmUrls( xml ); break; case CoverFetch::Yahoo: prepareYahooUrls( xml ); break; case CoverFetch::Discogs: prepareDiscogsUrls( xml ); break; } if( xml.hasError() ) { debug() << QString( "Error occured when pareparing %1 urls for %2: %3" ) .arg( sourceString(), (album() ? album()->name() : "'unknown'"), xml.errorString() ); debug() << urls(); } }
void FilePropertyWidgetQt::dragEnterEvent(QDragEnterEvent* event) { switch (property_->getAcceptMode()) { case FileProperty::AcceptMode::Save: { event->ignore(); return; } case FileProperty::AcceptMode::Open: { if (event->mimeData()->hasUrls()) { auto data = event->mimeData(); if (data->hasUrls()) { if (data->urls().size() > 0) { auto url = data->urls().first(); auto file = url.toLocalFile().toStdString(); switch (property_->getFileMode()) { case FileProperty::FileMode::AnyFile: case FileProperty::FileMode::ExistingFile: case FileProperty::FileMode::ExistingFiles: { auto ext = toLower(filesystem::getFileExtension(file)); for (const auto& filter : property_->getNameFilters()) { if (filter.extension_ == ext) { event->accept(); return; } } break; } case FileProperty::FileMode::Directory: case FileProperty::FileMode::DirectoryOnly: { if(filesystem::directoryExists(file)) { event->accept(); return; } break; } } } } } event->ignore(); return; } } }
void MainWindow::dropEvent(QDropEvent* event) { auto data = event->mimeData(); if (data->hasUrls() && data->urls().size() == 1) { QString path = data->urls().first().toLocalFile(); if (path.size() >= 2 && path[0] == '/' && path[1] == '/') path.remove(0, 1); if (QDir(path).exists()) { if (is_locked) { StopJudging(); QMessageBox::warning(this, "", QString("测评被终止!")); } LoadContest(path); } } }
void CanvasTabBar::dropEvent(QDropEvent *event) { auto mimeData = event->mimeData(); if (mimeData->hasUrls()) { _tabWidget->addCanvasesFromUrls(mimeData->urls()); event->acceptProposedAction(); } }
void SvnInternalCommitJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/) { initBeforeRun(); svn::Client cli(m_ctxt); std::vector<svn::Path> targets; QList<QUrl> l = urls(); foreach( const QUrl &u, l ) { QByteArray path = u.toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8(); targets.push_back( svn::Path( path.data() ) ); }
/** * Output the configuration file with this format * ------ * line 1: ns # number of servers * line 2: server_url_0 * line 3: server_url_1 * ... * line n: server_url_n-1 */ int xfer_write_server_url_file( std::string url_fname, std::string my_url, MPI_Comm comm) { int rc = 0; int rank, np; log_level debug_level = LOG_UNDEFINED; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &np); // output the config file if (!url_fname.empty()) { // gather the urls from all the servers std::string urls(NSSI_URL_LEN*np, '\0'); MPI_Gather(&my_url[0], NSSI_URL_LEN, MPI_CHAR, &urls[0], NSSI_URL_LEN, MPI_CHAR, 0, comm); // Write the urls to the config file if (rank == 0) { int i; std::string tmp_fname = url_fname + ".tmp"; std::ofstream urlfile (tmp_fname.c_str()); if (urlfile.is_open()) { // write the number of servers as the first line urlfile << np << std::endl; for (i=0; i<np; i++) { // extract the URL and write it to the config file size_t pos = i*NSSI_URL_LEN; std::string url = urls.substr(pos, NSSI_URL_LEN); log_debug(debug_level, "-- server %d : %s", i, url.c_str()); urlfile << url.c_str() << std::endl; } } else { log_error(debug_level, "Could not open server_url_file %s", url_fname.c_str()); MPI_Abort(comm, 1); } // close the file urlfile.close(); rename(tmp_fname.c_str(), url_fname.c_str()); } } return rc; }
void MainWindow::dropEvent(QDropEvent* event) { qDebug() << "Drop event"; auto mimeData = event->mimeData(); if (mimeData->hasUrls()) { QStringList pathList; auto urlList = mimeData->urls(); for (int i=0; i<urlList.size(); ++i) { pathList.append(urlList.at(i).toLocalFile()); } addTabs(pathList); } }
void DropImageWidget::dropEvent( QDropEvent *event ) { const QMimeData *mimeData = event->mimeData(); if( mimeData->hasUrls() ) { QList<QUrl> urls( mimeData->urls() ); if( urls.size() > 0 ) { emit droppedUrl( urls.at(0) ); event->acceptProposedAction(); } } }
// Independent function that takes a url from the list as a string // Checks if it has already been parsed // Returns true if found, else false bool check_urls(std::string x){ std::ifstream urls("urls.txt", std::ios::in); while (!urls.eof()){ std::string k; getline(urls, k); if (x == k){ urls.close(); return true; } } urls.close(); return false; }
void WWaveformViewer::dropEvent(QDropEvent * event) { if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() > 0) { QList<QUrl> urls(event->mimeData()->urls()); QUrl url = urls.first(); QString name = url.toLocalFile(); //If the file is on a network share, try just converting the URL to a string... if (name == "") name = url.toString(); event->accept(); emit(trackDropped(name, m_pGroup)); } else { event->ignore(); } }
void synthv1widget_preset::openPreset (void) { synthv1_config *pConfig = synthv1_config::getInstance(); if (pConfig == NULL) return; QString sFilename; const QString sExt(SYNTHV1_TITLE); const QString& sTitle = tr("Open Preset") + " - " SYNTHV1_TITLE; const QString& sFilter = tr("Preset files (*.%1)").arg(sExt); #if 1//QT_VERSION < 0x040400 QFileDialog::Options options = 0; if (pConfig->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; sFilename = QFileDialog::getOpenFileName(parentWidget(), sTitle, pConfig->sPresetDir, sFilter, NULL, options); #else QFileDialog fileDialog(nativeParentWidget(), sTitle, pConfig->sPresetDir, sFilter); fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFile); fileDialog.setDefaultSuffix(sExt); QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pConfig->sPresetDir)); fileDialog.setSidebarUrls(urls); if (pConfig->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); if (fileDialog.exec()) sFilename = fileDialog.selectedFiles().first(); #endif if (!sFilename.isEmpty()) { QFileInfo fi(sFilename); if (fi.exists() && queryPreset()) { const QString& sPreset = fi.completeBaseName(); pConfig->setPresetFile(sPreset, sFilename); emit loadPresetFile(sFilename); ++m_iInitPreset; // pConfig->sPreset = sPreset; pConfig->sPresetDir = fi.absolutePath(); setPreset(sPreset); refreshPreset(); } } stabilizePreset(); }
// Prompt for proper file list open. QStringList qtractorMidiListView::getOpenFileNames (void) { QStringList files; const QString sExt("mid"); const QString& sTitle = tr("Open MIDI Files") + " - " QTRACTOR_TITLE; QStringList filters; filters.append(tr("MIDI files (*.%1 *.smf *.midi)").arg(sExt)); filters.append(tr("All files (*.*)")); const QString& sFilter = filters.join(";;"); QWidget *pParentWidget = NULL; QFileDialog::Options options = 0; qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions && pOptions->bDontUseNativeDialogs) { options |= QFileDialog::DontUseNativeDialog; pParentWidget = QWidget::window(); } #if 1//QT_VERSION < 0x040400 // Ask for the filenames to open... files = QFileDialog::getOpenFileNames(pParentWidget, sTitle, recentDir(), sFilter, NULL, options); #else // Construct open-files dialog... QFileDialog fileDialog(pParentWidget, sTitle, recentDir(), sFilter); // Set proper open-file modes... fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFiles); fileDialog.setDefaultSuffix(sExt); // Stuff sidebar... if (pOptions) { QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pOptions->sSessionDir)); urls.append(QUrl::fromLocalFile(pOptions->sMidiDir)); fileDialog.setSidebarUrls(urls); } fileDialog.setOptions(options); // Show dialog... if (fileDialog.exec()) files = fileDialog.selectedFiles(); #endif return files; }
// Drag move event, happens when a dragged item hovers over the track sources view... void WLibrarySidebar::dragMoveEvent(QDragMoveEvent * event) { //qDebug() << "dragMoveEvent" << event->mimeData()->formats(); // Start a timer to auto-expand sections the user hovers on. QPoint pos = event->pos(); QModelIndex index = indexAt(pos); if (m_hoverIndex != index) { m_expandTimer.stop(); m_hoverIndex = index; m_expandTimer.start(expand_time, this); } // This has to be here instead of after, otherwise all drags will be // rejected -- rryan 3/2011 QTreeView::dragMoveEvent(event); if (event->mimeData()->hasUrls()) { QList<QUrl> urls(event->mimeData()->urls()); // Drag and drop within this widget if ((event->source() == this) && (event->possibleActions() & Qt::MoveAction)) { // Do nothing. event->ignore(); } else { SidebarModel* sidebarModel = dynamic_cast<SidebarModel*>(model()); bool accepted = true; if (sidebarModel) { accepted = false; foreach (QUrl url, urls) { QModelIndex destIndex = this->indexAt(event->pos()); if (sidebarModel->dragMoveAccept(destIndex, url)) { // We only need one URL to be valid for us // to accept the whole drag... // consider we have a long list of valid files, checking all will // take a lot of time that stales Mixxx and this makes the drop feature useless // Eg. you may have tried to drag two MP3's and an EXE, the drop is accepted here, // but the EXE is sorted out later after dropping accepted = true; break; } } } if (accepted) { event->acceptProposedAction(); } else { event->ignore(); } }
BObjectList<PootleTranslationProject> PootleProject::TranslationProjects() { BMessage tprojects; mData.FindMessage("translation_projects", &tprojects); BObjectList<BString> urls(20, true); int32 count = tprojects.CountNames(B_ANY_TYPE); char buffer[33]; for (int32 i = 0; i < count; i++) { sprintf(buffer, "%d", i); urls.AddItem(new BString(tprojects.GetString(buffer, ""))); } return mEndpoint->API()->TranslationProjects()->GetByList(urls); }
void CoverWidget::dropEvent(QDropEvent *e) { auto mimeData = e->mimeData(); QImage img; if (mimeData->hasImage()) { img = qvariant_cast<QImage>(mimeData->imageData()); } else { const auto &urls = mimeData->urls(); if (urls.size() == 1) { auto &url = urls.at(0); if (url.isLocalFile()) { img = App::readImage(psConvertFileUrl(url)); } } } if (!_dropArea->hiding()) { _dropArea->hideAnimated(func(this, &CoverWidget::dropAreaHidden)); } e->acceptProposedAction(); showSetPhotoBox(img); }
// Browse for audio clip filename. void qtractorClipForm::browseFilename (void) { QString sType; QString sExt; QString sFilter; qtractorTrack::TrackType clipType = trackType(); switch (clipType) { case qtractorTrack::Audio: sType = tr("Audio"); sExt = qtractorAudioFileFactory::defaultExt(); sFilter = qtractorAudioFileFactory::filters(); break; case qtractorTrack::Midi: sType = tr("MIDI"); sExt = "mid"; sFilter = tr("MIDI files (*.%1 *.smf *.midi)").arg(sExt); break; case qtractorTrack::None: default: return; } // Browse for file... QString sFilename; const QString& sTitle = tr("%1 Clip File").arg(sType) + " - " QTRACTOR_TITLE; #if 1//QT_VERSION < 0x040400 QFileDialog::Options options = 0; qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions && pOptions->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; sFilename = QFileDialog::getOpenFileName(this, sTitle, m_ui.FilenameComboBox->currentText(), sFilter, NULL, options); #else QFileDialog fileDialog(this, sTitle, m_ui.FilenameComboBox->currentText(), sFilter); // Set proper open-file modes... fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFile); fileDialog.setDefaultSuffix(sExt); // Stuff sidebar... qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions) { QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pOptions->sSessionDir)); switch (clipType) { case qtractorTrack::Audio: urls.append(QUrl::fromLocalFile(pOptions->sAudioDir)); break; case qtractorTrack::Midi: urls.append(QUrl::fromLocalFile(pOptions->sMidiDir)); break; case qtractorTrack::None: default: break; } fileDialog.setSidebarUrls(urls); if (pOptions->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); } // Show dialog... if (fileDialog.exec()) sFilename = fileDialog.selectedFiles().first(); #endif if (!sFilename.isEmpty()) { m_ui.FilenameComboBox->setEditText(sFilename); m_ui.FilenameComboBox->setFocus(); // changed(); } }
void BookmarkManager::setBookmarks(const QList<ConferenceBookmark>& conferences) { setBookmarks(urls(), conferences); }
// Import new intrument file(s) into listing. void qtractorMidiControlForm::importSlot (void) { qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions == NULL) return; QStringList files; const QString sExt("qtc"); const QString& sTitle = tr("Import Controller Files") + " - " QTRACTOR_TITLE; const QString& sFilter = tr("Controller files (*.%1)").arg(sExt); #if 1//QT_VERSION < 0x040400 // Ask for the filename to open... QFileDialog::Options options = 0; if (pOptions->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; files = QFileDialog::getOpenFileNames(this, sTitle, pOptions->sMidiControlDir, sFilter, NULL, options); #else // Construct open-files dialog... QFileDialog fileDialog(this, sTitle, pOptions->sMidiControlDir, sFilter); // Set proper open-file modes... fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFiles); fileDialog.setHistory(pOptions->midiControlFiles); fileDialog.setDefaultSuffix(sExt); // Stuff sidebar... QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pOptions->sSessionDir)); urls.append(QUrl::fromLocalFile(pOptions->sMidiControlDir)); fileDialog.setSidebarUrls(urls); if (pOptions->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); // Show dialog... if (fileDialog.exec()) files = fileDialog.selectedFiles(); #endif if (files.isEmpty()) return; // Remember this last directory... // For avery selected controller file to load... QTreeWidgetItem *pItem = NULL; QStringListIterator iter(files); while (iter.hasNext()) { // Merge the file contents into global container... const QString& sPath = iter.next(); // Start inserting in the current selected or last item... if (pItem == NULL) pItem = m_ui.FilesListView->currentItem(); if (pItem == NULL) { int iLastItem = m_ui.FilesListView->topLevelItemCount() - 1; if (iLastItem >= 0) pItem = m_ui.FilesListView->topLevelItem(iLastItem); } // New item on the block :-) pItem = new QTreeWidgetItem(m_ui.FilesListView, pItem); if (pItem) { QFileInfo info(sPath); pItem->setIcon(0, QIcon(":/images/itemFile.png")); pItem->setText(0, info.completeBaseName()); pItem->setText(1, sPath); m_ui.FilesListView->setCurrentItem(pItem); pOptions->sMidiControlDir = info.absolutePath(); } } // Make effect immediately. reloadSlot(); }
// Export the whole state into a single controller file. void qtractorMidiControlForm::exportSlot (void) { qtractorMidiControl *pMidiControl = qtractorMidiControl::getInstance(); if (pMidiControl == NULL) return; qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions == NULL) return; QString sPath; const QString sExt("qtc"); const QString& sTitle = tr("Export Controller File") + " - " QTRACTOR_TITLE; const QString& sFilter = tr("Controller files (*.%1)").arg(sExt); if (pOptions->midiControlFiles.isEmpty()) { sPath = QFileInfo(pOptions->sMidiControlDir, tr("controller") + '.' + sExt).absoluteFilePath(); } else sPath = pOptions->midiControlFiles.last(); #if 1//QT_VERSION < 0x040400 // Ask for the filename to open... QFileDialog::Options options = 0; if (pOptions->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; sPath = QFileDialog::getSaveFileName(this, sTitle, sPath, sFilter, NULL, options); #else // Construct open-files dialog... QFileDialog fileDialog(this, sTitle, sPath, sFilter); // Set proper open-file modes... fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setHistory(pOptions->midiControlFiles); fileDialog.setDefaultSuffix(sExt); // Stuff sidebar... QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pOptions->sSessionDir)); urls.append(QUrl::fromLocalFile(pOptions->sMidiControlDir)); fileDialog.setSidebarUrls(urls); if (pOptions->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); // Show dialog... if (fileDialog.exec()) sPath = fileDialog.selectedFiles().first(); else sPath.clear(); #endif if (sPath.isEmpty()) return; // Enforce .qtc extension... if (QFileInfo(sPath).suffix().isEmpty()) { sPath += '.' + sExt; // Check if already exists... if (QFileInfo(sPath).exists()) { if (QMessageBox::warning(this, tr("Warning") + " - " QTRACTOR_TITLE, tr("The controller file already exists:\n\n" "\"%1\"\n\n" "Do you want to replace it?") .arg(sPath), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) return; } } // Just save the whole bunch... if (pMidiControl->saveDocument(sPath)) { pOptions->sMidiControlDir = QFileInfo(sPath).absolutePath(); if (m_iDirtyMap > 0 && QMessageBox::warning(this, tr("Warning") + " - " QTRACTOR_TITLE, tr("Saved controller mappings may not be effective\n" "the next time you start this program.\n\n" "\"%1\"\n\n" "Do you want to apply to controller files?") .arg(sPath), QMessageBox::Apply | QMessageBox::Ignore) == QMessageBox::Apply) { // Apply by append... pOptions->midiControlFiles.clear(); pOptions->midiControlFiles.append(sPath); // Won't be dirty anymore. m_iDirtyMap = 0; // Make it renew... refreshFiles(); reloadSlot(); } } }
void MainWindow::dragEnterEvent(QDragEnterEvent* event) { auto data = event->mimeData(); if (data->hasUrls() && data->urls().size() == 1 && QDir(data->urls().at(0).toLocalFile()).exists()) event->acceptProposedAction(); else event->ignore(); }
// Import new intrument file(s) into listing. void qtractorInstrumentForm::importSlot (void) { if (m_pInstruments == NULL) return; qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions == NULL) return; QStringList files; const QString sExt("ins"); const QString& sTitle = tr("Import Instrument Files") + " - " QTRACTOR_TITLE; const QString& sFilter = tr("Instrument files (*.%1 *.sf2 *.midnam)").arg(sExt); #if 1//QT_VERSION < 0x040400 // Ask for the filename to open... QFileDialog::Options options = 0; if (pOptions->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; files = QFileDialog::getOpenFileNames(this, sTitle, pOptions->sInstrumentDir, sFilter, NULL, options); #else // Construct open-files dialog... QFileDialog fileDialog(this, sTitle, pOptions->sInstrumentDir, sFilter); // Set proper open-file modes... fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFiles); fileDialog.setDefaultSuffix(sExt); // Stuff sidebar... QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pOptions->sSessionDir)); urls.append(QUrl::fromLocalFile(pOptions->sInstrumentDir)); fileDialog.setSidebarUrls(urls); if (pOptions->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); // Show dialog... if (fileDialog.exec()) files = fileDialog.selectedFiles(); #endif if (files.isEmpty()) return; // Tell that we may take some time... QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); // For avery selected instrument file to load... QTreeWidgetItem *pItem = NULL; QStringListIterator iter(files); while (iter.hasNext()) { // Merge the file contents into global container... const QString& sPath = iter.next(); if (m_pInstruments->load(sPath)) { // Start inserting in the current selected or last item... if (pItem == NULL) pItem = m_ui.FilesListView->currentItem(); if (pItem == NULL) { int iLastItem = m_ui.FilesListView->topLevelItemCount() - 1; if (iLastItem >= 0) pItem = m_ui.FilesListView->topLevelItem(iLastItem); } // New item on the block :-) pItem = new QTreeWidgetItem(m_ui.FilesListView, pItem); if (pItem) { QFileInfo info(sPath); pItem->setIcon(0, QIcon(":/images/itemFile.png")); pItem->setText(0, info.completeBaseName()); pItem->setText(1, sPath); m_ui.FilesListView->setCurrentItem(pItem); pOptions->sInstrumentDir = info.absolutePath(); ++m_iDirtyCount; } } } // May refresh the whole form? refreshForm(); stabilizeForm(); // Done waiting. QApplication::restoreOverrideCursor(); }
// Export the whole state into a single instrument file. void qtractorInstrumentForm::exportSlot (void) { if (m_pInstruments == NULL) return; qtractorOptions *pOptions = qtractorOptions::getInstance(); if (pOptions == NULL) return; QString sPath; const QString sExt("ins"); const QString& sTitle = tr("Export Instrument File") + " - " QTRACTOR_TITLE; const QString& sFilter = tr("Instrument files (*.%1)").arg(sExt); #if 1//QT_VERSION < 0x040400 // Ask for the filename to open... QFileDialog::Options options = 0; if (pOptions->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; sPath = QFileDialog::getSaveFileName(this, sTitle, pOptions->sInstrumentDir, sFilter, NULL, options); #else // Construct open-files dialog... QFileDialog fileDialog(this, sTitle, pOptions->sInstrumentDir, sFilter); // Set proper open-file modes... fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setDefaultSuffix(sExt); // Stuff sidebar... QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pOptions->sSessionDir)); urls.append(QUrl::fromLocalFile(pOptions->sInstrumentDir)); fileDialog.setSidebarUrls(urls); if (pOptions->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); // Show dialog... if (fileDialog.exec()) sPath = fileDialog.selectedFiles().first(); #endif if (sPath.isEmpty() || sPath.at(0) == '.') return; // Enforce .ins extension... if (QFileInfo(sPath).suffix().isEmpty()) { sPath += '.' + sExt; // Check if already exists... if (QFileInfo(sPath).exists()) { if (QMessageBox::warning(this, tr("Warning") + " - " QTRACTOR_TITLE, tr("The instrument file already exists:\n\n" "\"%1\"\n\n" "Do you want to replace it?") .arg(sPath), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) return; } } // Tell that we may take some time... QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); // Just save the whole bunch... if (m_pInstruments->save(sPath)) pOptions->sInstrumentDir = QFileInfo(sPath).absolutePath(); // Done with export. QApplication::restoreOverrideCursor(); }
void synthv1widget_preset::savePreset ( const QString& sPreset ) { if (sPreset.isEmpty()) return; synthv1_config *pConfig = synthv1_config::getInstance(); if (pConfig == NULL) return; const QString sExt(SYNTHV1_TITLE); QFileInfo fi(QDir(pConfig->sPresetDir), sPreset + '.' + sExt); QString sFilename = fi.absoluteFilePath(); if (!fi.exists()) { const QString& sTitle = tr("Save Preset") + " - " SYNTHV1_TITLE; const QString& sFilter = tr("Preset files (*.%1)").arg(sExt); #if 1//QT_VERSION < 0x040400 QFileDialog::Options options = 0; if (pConfig->bDontUseNativeDialogs) options |= QFileDialog::DontUseNativeDialog; sFilename = QFileDialog::getSaveFileName(parentWidget(), sTitle, sFilename, sFilter, NULL, options); #else QFileDialog fileDialog(nativeParentWidget(), sTitle, sFilename, sFilter); fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setDefaultSuffix(sExt); QList<QUrl> urls(fileDialog.sidebarUrls()); urls.append(QUrl::fromLocalFile(pConfig->sPresetDir)); fileDialog.setSidebarUrls(urls); if (pConfig->bDontUseNativeDialogs) fileDialog.setOptions(QFileDialog::DontUseNativeDialog); if (fileDialog.exec()) sFilename = fileDialog.selectedFiles().first(); #endif } else { if (QMessageBox::warning(parentWidget(), tr("Warning") + " - " SYNTHV1_TITLE, tr("About to replace preset:\n\n" "\"%1\"\n\n" "Are you sure?") .arg(sPreset), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) { sFilename.clear(); } } if (!sFilename.isEmpty()) { if (QFileInfo(sFilename).suffix() != sExt) sFilename += '.' + sExt; emit savePresetFile(sFilename); pConfig->setPresetFile(sPreset, sFilename); ++m_iInitPreset; pConfig->sPreset = sPreset; pConfig->sPresetDir = QFileInfo(sFilename).absolutePath(); refreshPreset(); } stabilizePreset(); }