Exemplo n.º 1
0
void MainWindow::on_actionCloudstorageopen_triggered()
{
	if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
		return;

	QString filename;
	if (getCloudURL(filename)) {
		getNotificationWidget()->showNotification(get_error_string(), KMessageWidget::Error);
		return;
	}
	qDebug() << filename;

	closeCurrentFile();

	int error;

	QByteArray fileNamePtr = QFile::encodeName(filename);
	error = parse_file(fileNamePtr.data());
	if (!error) {
		set_filename(fileNamePtr.data(), true);
		setTitle(MWTF_FILENAME);
	}
	getNotificationWidget()->hideNotification();
	process_dives(false, false);
	refreshDisplay();
	ui.actionAutoGroup->setChecked(autogroup);
}
Exemplo n.º 2
0
void MainWindow::on_actionOpen_triggered()
{
	if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
		return;

	// yes, this look wrong to use getSaveFileName() for the open dialog, but we need to be able
	// to enter file names that don't exist in order to use our git syntax /path/to/dir[branch]
	// with is a potentially valid input, but of course won't exist. So getOpenFileName() wouldn't work
	QFileDialog dialog(this, tr("Open file"), lastUsedDir(), filter());
	dialog.setFileMode(QFileDialog::AnyFile);
	dialog.setViewMode(QFileDialog::Detail);
	dialog.setLabelText(QFileDialog::Accept, tr("Open"));
	dialog.setLabelText(QFileDialog::Reject, tr("Cancel"));
	QStringList filenames;
	if (dialog.exec())
		filenames = dialog.selectedFiles();
	if (filenames.isEmpty())
		return;
	updateLastUsedDir(QFileInfo(filenames.first()).dir().path());
	closeCurrentFile();
	loadFiles(filenames);
}
Exemplo n.º 3
0
bool ZipFile::extractCurrentFile(const std::string& path, bool whiny)
{    
    int ret;
    unz_file_info info;
    char fname[1024];

    try {
        internal::api("unzGetCurrentFileInfo", unzGetCurrentFileInfo(this->fp, &info, fname, 1024, nullptr, 0, nullptr, 0));
        
        std::string outPath(path);
        fs::addnode(outPath, fname);

        TraceL << "Extracting asset: " << outPath << endl;

        // Create directory
#if !WIN32
        const int FILE_ATTRIBUTE_DIRECTORY = 0x10;
#endif
        if (info.external_fa & FILE_ATTRIBUTE_DIRECTORY || 
            fname[strlen(fname) - 1] == fs::delimiter) {
            TraceL << "Create directory: " << outPath << endl;
            fs::mkdirr(outPath);
        }

        // Create file
        else {            
            TraceL << "Create file: " << outPath << endl;

            // Note: If this fails the file we are trying 
            // to write may be in use on the filesystem.
            openCurrentFile();

            std::ofstream ofs(outPath, std::ios::binary | std::ios::out);

            // FIX: FILE_ATTRIBUTE_DIRECTORY can be inconsistent, so we 
            // need to be ready to create directories if the output file 
            // fails to open.
            if (!ofs.is_open()) {
                fs::mkdirr(fs::dirname(outPath));
                ofs.open(outPath);
            }

            if (!ofs.is_open())
                throw std::runtime_error("Cannot open zip output file: " + outPath);
            
            char buffer[16384];
            while ((ret = unzReadCurrentFile(this->fp, buffer, 16384)) > 0)
                ofs.write(buffer, ret);
            
            ofs.close();
            
            internal::api("unzReadCurrentFile", ret); // throw file read errors
            closeCurrentFile();
        }
    } 
    catch (std::exception& exc) {
        ErrorL << "Cannot unzip file: " << exc.what() << endl;
        if (whiny)
            throw exc;
        return false;
    }
    return true;
}
//-------------------------------------------------------------------------
void CloseFileGuiCommand::exitApplication ()
{
    if (closeCurrentFile ())
        QApplication::exit ();
}
//-------------------------------------------------------------------------
void CloseFileGuiCommand::closeFile ()
{
    closeCurrentFile ();
}
Exemplo n.º 6
0
void MainWindow::on_actionClose_triggered()
{
	if (okToClose(tr("Please save or cancel the current dive edit before closing the file.")))
		closeCurrentFile();
}