| 116 | } |
| 117 | |
| 118 | bool ExportDialog::mayWriteFile(const QString &fname, bool inSeparateFiles) |
| 119 | { |
| 120 | QFileInfo fi(fname); |
| 121 | QString dirname(fname); |
| 122 | if (!inSeparateFiles) { |
| 123 | if (fi.exists()) { |
| 124 | if (fi.isFile()) { |
| 125 | xcaWarningBox msg(NULL, |
| 126 | tr("The file: '%1' already exists!").arg(fname)); |
| 127 | msg.addButton(QMessageBox::Ok, tr("Overwrite")); |
| 128 | msg.addButton(QMessageBox::Cancel, tr("Do not overwrite")); |
| 129 | if (msg.exec() != QMessageBox::Ok) |
| 130 | return false; |
| 131 | } else { |
| 132 | XCA_ERROR(tr("The path: '%1' exist, but is not a file") |
| 133 | .arg(nativeSeparator(fname))); |
| 134 | return false; |
| 135 | } |
| 136 | } |
| 137 | dirname = fi.path(); |
| 138 | } |
| 139 | |
| 140 | QFileInfo dir(dirname); |
| 141 | qDebug() << "Checking" << fname << dirname << "isDir" << dir.isDir() << "exists" << dir.exists(); |
| 142 | if (dir.isDir()) |
| 143 | return true; |
| 144 | if (dir.exists()) { |
| 145 | XCA_ERROR(tr("The path: '%1' exist, but is not a directory") |
| 146 | .arg(nativeSeparator(fname))); |
| 147 | return false; |
| 148 | } |
| 149 | xcaWarningBox msg(NULL, |
| 150 | tr("The directory: '%1' does not exist. Should it be created?") |
| 151 | .arg(nativeSeparator(dirname))); |
| 152 | msg.addButton(QMessageBox::Ok, tr("Create")); |
| 153 | msg.addButton(QMessageBox::Cancel); |
| 154 | if (msg.exec() != QMessageBox::Ok) |
| 155 | return false; |
| 156 | |
| 157 | if (!QDir().mkpath(dirname)) { |
| 158 | xcaWarningBox msg(NULL, tr("Failed to create directory '%1'") |
| 159 | .arg(nativeSeparator(fname))); |
| 160 | msg.exec(); |
| 161 | return false; |
| 162 | } |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | void ExportDialog::accept() |
| 167 | { |