Skip to content

Commit

Permalink
Merge pull request #191 from kanurag94/unify_open_save
Browse files Browse the repository at this point in the history
Unify open/ open image and save/ save image
  • Loading branch information
kovzol authored Jul 21, 2020
2 parents 096e5c1 + ab8af5a commit 8e1ad7b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
16 changes: 5 additions & 11 deletions src/ui-hlp/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static menudialog *uih_perturbationdialog, *uih_juliadialog,
*uih_filterdialog, *uih_shiftdialog, *uih_speeddialog, *printdialog,
*uih_bailoutdialog, *uih_threaddialog, *saveanimdialog, *uih_juliamodedialog,
*uih_textposdialog, *uih_fastmodedialog, *uih_timedialog, *uih_numdialog,
*uih_fpdialog, *palettedialog, *uih_cyclingdialog, *loadimgdialog, *palettegradientdialog,
*uih_fpdialog, *palettedialog, *uih_cyclingdialog, *palettegradientdialog,
*uih_renderimgdialog
#ifdef USE_SFFE
,
Expand Down Expand Up @@ -177,17 +177,13 @@ void uih_registermenudialogs_i18n(void)
NULL_I();

Register(loaddialog);
DIALOGIFILE_I(TR("Dialog", "Filename:"), "fract*.xpf");
DIALOGIFILE_I(TR("Dialog", "Filename:"), "*.png *.xpf");
NULL_I();

Register(playdialog);
DIALOGIFILE_I(TR("Dialog", "Filename:"), "anim*.xaf");
NULL_I();

Register(loadimgdialog);
DIALOGIFILE_I(TR("Dialog", "Filename:"), "fract*.png");
NULL_I();

Register(saveimgdialog);
DIALOGOFILE_I(TR("Dialog", "Filename:"), "fract*.png");
NULL_I();
Expand Down Expand Up @@ -1110,18 +1106,16 @@ void uih_registermenus_i18n(void)
loaddialog);
MENUDIALOG_I("file", NULL, TR("Menu", "Save"), "savepos", 0,
uih_saveposfile, saveposdialog);
SUBMENU_I("file", NULL, TR("Menu", "Save as"), "saveas");
MENUDIALOG_I("saveas", NULL, TR("Menu", "PNG"), "saveimg", 0,
uih_savepngfile, saveimgdialog);
MENUSEPARATOR_I("file")
MENUDIALOGCB_I("file", NULL, TR("Menu", "Record"), "record", 0,
uih_saveanimfile, saveanimdialog, uih_saveanimenabled);
MENUDIALOG_I("file", NULL, TR("Menu", "Replay"), "play",
MENUFLAG_INTERRUPT | MENUFLAG_NOPLAY, uih_playfile,
playdialog);
MENUSEPARATOR_I("file");
MENUDIALOG_I("file", NULL, TR("Menu", "Open image"), "loadimg",
MENUFLAG_INTERRUPT, uih_loadpngfile, loadimgdialog);
MENUDIALOG_I("file", NULL, TR("Menu", "Save image"), "saveimg", 0,
uih_savepngfile, saveimgdialog);
MENUSEPARATOR_I("file");
MENUDIALOG_I("file", NULL, TR("Menu", "Render"), "renderanim", UI,
uih_render, uih_renderdialog);
MENUDIALOG_I("file", NULL, TR("Menu", "Render Image"), "renderimg", UI,
Expand Down
10 changes: 10 additions & 0 deletions src/ui-hlp/ui_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,16 @@ void uih_cycling_continue(struct uih_context *c)

void uih_loadfile(struct uih_context *c, xio_constpath d)
{
int los = strlen(d);
char ext[4];
if(los < 3)
return;
memcpy(ext, &d[los-3], 3);
if(strcmp(ext, "png") == 0) {
uih_loadpngfile(c, d);
return;
}

xio_file f;
f = xio_ropen(d);
if (f == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/customdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ void CustomDialog::chooseInputFile()
QSettings settings;
QString fileLocation = settings.value("MainWindow/lastFileLocation", QDir::homePath()).toString();
QString fileName = QFileDialog::getOpenFileName(
this, sender()->objectName(), fileLocation, "*.xpf *.xaf");
this, sender()->objectName(), fileLocation, "*.xpf *.png *.xaf");
if (!fileName.isNull()) {
field->setText(fileName);
settings.setValue("MainWindow/lastFileLocation", QFileInfo(fileName).absolutePath());
Expand Down
3 changes: 2 additions & 1 deletion src/ui/image_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const char *writepng(xio_constpath filename, const struct image *image, xio_file
QString xpf_chunk = xio_getstring(xpf_data);
qimage->setText("Metadata", xpf_chunk);
}
qimage->save(filename);
if(!qimage->save(filename))
return "Invalid file extension";
return NULL;
}

Expand Down
6 changes: 4 additions & 2 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ void MainWindow::showDialog(const char *name)
(dialog[0].type == DIALOG_IFILE || dialog[0].type == DIALOG_OFILE)) {
QString filter =
QString("*.%1").arg(QFileInfo(dialog[0].defstr).completeSuffix());

QSettings settings;
QString fileLocation =
settings.value("MainWindow/lastFileLocation", QDir::homePath())
Expand All @@ -848,8 +847,11 @@ void MainWindow::showDialog(const char *name)

if (!fileName.isNull()) {
QString ext = "." + QFileInfo(dialog[0].defstr).suffix();
if (!fileName.endsWith(ext))

if (!fileName.endsWith(".xpf") and !fileName.endsWith(".png")
and !fileName.endsWith(ext))
fileName += ext;

dialogparam *param = (dialogparam *)malloc(sizeof(dialogparam));
param->dstring = strdup(fileName.toUtf8());
menuActivate(item, param);
Expand Down

0 comments on commit 8e1ad7b

Please sign in to comment.