Skip to content

Commit

Permalink
Do not perform any opening actions when project is being opened with …
Browse files Browse the repository at this point in the history
…an error (#653)
  • Loading branch information
Kicer86 committed Jun 8, 2024
1 parent ffa1f4d commit 4945d26
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 50 deletions.
58 changes: 32 additions & 26 deletions src/gui/desktop/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,25 @@ void MainWindow::openProject(const QString& prjPath, bool is_new)
{
closeProject();

// setup search path prefix
assert( QDir::searchPaths("prj").isEmpty() == true );
QDir::setSearchPaths("prj", { prjInfo.getBaseDir() } );
auto open_status = m_prjManager->open(prjInfo);

m_currentPrj = std::move(open_status.first);
projectOpened(open_status.second, is_new);
if (open_status.second)
{
// setup search path prefix
QDir::setSearchPaths("prj", { prjInfo.getBaseDir() } );

m_currentPrj = std::move(open_status.first);
projectOpened(is_new);

// add project to list of recent projects
QStringList projects = ObjectsAccessor::instance().recentProjects();
projects.removeAll(prjInfo.getPath()); // remove entry if it alredy exists
projects.prepend(prjInfo.getPath()); // add it at the beginning
ObjectsAccessor::instance().setRecentProjects(projects);
// add project to list of recent projects
QStringList projects = ObjectsAccessor::instance().recentProjects();
projects.removeAll(prjInfo.getPath()); // remove entry if it alredy exists
projects.prepend(prjInfo.getPath()); // add it at the beginning
ObjectsAccessor::instance().setRecentProjects(projects);
}
else
showProjectOpeningError(prjPath, open_status.second);
}
}

Expand Down Expand Up @@ -372,20 +378,27 @@ void MainWindow::on_actionConfiguration_triggered()
}


void MainWindow::projectOpened(const Database::BackendStatus& status, bool is_new)
void MainWindow::projectOpened(bool is_new)
{
Database::IDatabase& db = m_currentPrj->getDatabase();

emit currentDatabaseChanged(&db);
emit currentProjectChanged(m_currentPrj.get());

// TODO: I do not like this flag here...
if (is_new)
on_actionScan_collection_triggered();

updateGui();
}

void MainWindow::showProjectOpeningError(const QString& prjPath, const Database::BackendStatus& status)
{
switch(status.get())
{
case Database::StatusCodes::Ok:
{
Database::IDatabase& db = m_currentPrj->getDatabase();

emit currentDatabaseChanged(&db);
emit currentProjectChanged(m_currentPrj.get());

// TODO: I do not like this flag here...
if (is_new)
on_actionScan_collection_triggered();
assert(!"Error was expected");
break;
}

Expand All @@ -396,7 +409,6 @@ void MainWindow::projectOpened(const Database::BackendStatus& status, bool is_ne
"It means your application is too old to open it.\n\n"
"Please upgrade application to open this collection.")
);
closeProject();
break;

case Database::StatusCodes::VersionTooOld:
Expand All @@ -405,7 +417,6 @@ void MainWindow::projectOpened(const Database::BackendStatus& status, bool is_ne
tr("Photo collection you are trying to open uses database in version which is not supported.\n"
"It means your database is too old to open it.\n\n")
);
closeProject();
break;

case Database::StatusCodes::OpenFailed:
Expand All @@ -414,9 +425,8 @@ void MainWindow::projectOpened(const Database::BackendStatus& status, bool is_ne
tr("Photo collection could not be opened.\n"
"It usually means that collection files are broken\n"
"or you don't have rights to access them.\n\n"
"Please check collection files:\n%1").arg(m_currentPrj->getProjectInfo().getPath())
"Please check collection files:\n%1").arg(prjPath)
);
closeProject();
break;

case Database::StatusCodes::ProjectLocked:
Expand All @@ -425,7 +435,6 @@ void MainWindow::projectOpened(const Database::BackendStatus& status, bool is_ne
tr("Photo collection could not be opened.\n"
"It is already opened by another Photo Broom instance.")
);
closeProject();
break;

default:
Expand All @@ -435,9 +444,6 @@ void MainWindow::projectOpened(const Database::BackendStatus& status, bool is_ne
"Please report a bug.\n"
"Error code: %1").arg(static_cast<int>( status.get()) )
);
closeProject();
break;
}

updateGui();
}
3 changes: 2 additions & 1 deletion src/gui/desktop/ui/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class MainWindow: public QObject
void on_actionConfiguration_triggered();

//internal slots
void projectOpened(const Database::BackendStatus &, bool);
void projectOpened(bool);
void showProjectOpeningError(const QString& prjPath, const Database::BackendStatus &);

//check version
void checkVersion();
Expand Down
28 changes: 14 additions & 14 deletions tr/photo_broom_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,54 +424,54 @@ Please check your internet connection.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="321"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="327"/>
<source>Open collection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="321"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="327"/>
<source>Photo Broom files (*.bpj)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="359"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="365"/>
<source>About Photo Broom</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="365"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="371"/>
<source>About Qt</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="394"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="404"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="407"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="416"/>
<source>Unsupported photo collection version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="395"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="408"/>
<source>Photo collection you are trying to open uses database in version which is not supported.
It means your application is too old to open it.

Please upgrade application to open this collection.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="405"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="417"/>
<source>Photo collection you are trying to open uses database in version which is not supported.
It means your database is too old to open it.

</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="413"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="424"/>
<source>Could not open collection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="414"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="425"/>
<source>Photo collection could not be opened.
It usually means that collection files are broken
or you don&apos;t have rights to access them.
Expand All @@ -481,23 +481,23 @@ Please check collection files:
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="424"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="434"/>
<source>Collection locked</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="425"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="435"/>
<source>Photo collection could not be opened.
It is already opened by another Photo Broom instance.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="433"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="442"/>
<source>Unexpected error</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="434"/>
<location filename="../src/gui/desktop/ui/mainwindow.cpp" line="443"/>
<source>An unexpected error occured while opening photo collection.
Please report a bug.
Error code: %1</source>
Expand Down
18 changes: 9 additions & 9 deletions tr/photo_broom_pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ Please check your internet connection.</source>
Sprawdź proszę swoje połączenie z internetem.</translation>
</message>
<message>
<location line="+119"/>
<location line="+125"/>
<source>Open collection</source>
<translation>Otwórz kolekcję</translation>
</message>
Expand All @@ -441,13 +441,13 @@ Sprawdź proszę swoje połączenie z internetem.</translation>
<translation>Pliki Photo Broom (*.bpj)</translation>
</message>
<message>
<location line="+73"/>
<location line="+10"/>
<location line="+80"/>
<location line="+9"/>
<source>Unsupported photo collection version</source>
<translation>Nieobsługiwana wersja kolekcji</translation>
</message>
<message>
<location line="-9"/>
<location line="-8"/>
<source>Photo collection you are trying to open uses database in version which is not supported.
It means your application is too old to open it.

Expand All @@ -458,7 +458,7 @@ Oznacza to, że twoja aplikacja jest zbyt stara aby ją otworzyć.
Proszę zaktualizować aplikację.</translation>
</message>
<message>
<location line="+10"/>
<location line="+9"/>
<source>Photo collection you are trying to open uses database in version which is not supported.
It means your database is too old to open it.

Expand All @@ -469,7 +469,7 @@ Oznacza to, że twoja aplikacja jest zbyt stara aby ją otworzyć.
</translation>
</message>
<message>
<location line="+8"/>
<location line="+7"/>
<source>Could not open collection</source>
<translation>Nie otwarto kolekcji zdjęć</translation>
</message>
Expand All @@ -489,7 +489,7 @@ Sprawdź proszę pliki kolekcji:
%1</translation>
</message>
<message>
<location line="+10"/>
<location line="+9"/>
<source>Collection locked</source>
<translation>Kolekcja w użyciu</translation>
</message>
Expand All @@ -500,7 +500,7 @@ It is already opened by another Photo Broom instance.</source>
<translation>Kolekcja zdjęć nie mogła zostać otwarta ponieważ jest już używana.</translation>
</message>
<message>
<location line="+9"/>
<location line="+8"/>
<source>An unexpected error occured while opening photo collection.
Please report a bug.
Error code: %1</source>
Expand All @@ -514,7 +514,7 @@ Kod błędu: %1</translation>
<translation>Niespodziewany błąd</translation>
</message>
<message>
<location line="-74"/>
<location line="-77"/>
<source>About Photo Broom</source>
<translation>O programie</translation>
</message>
Expand Down

0 comments on commit 4945d26

Please sign in to comment.