Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit d9bfbfa8 authored by saubatn's avatar saubatn
Browse files

NEW : Applications now store in its settings file extensions that are it handles.

NEW : When autoloading component extensions the application prompts the user whether the application is associated with them for file opening.
FIXED : at the moment, the prompt is done only for Windows user (TODO Linux & MacOS)

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@547 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 8de1af27
......@@ -36,6 +36,7 @@
#include <QtGui>
#include <QSettings>
#include <QApplication>
#include <boost/concept_check.hpp>
namespace camitk {
......@@ -398,10 +399,10 @@ void ExtensionManager::unloadAllActionExtensions() {
// -------------------- registerFileExtension --------------------
void ExtensionManager::registerFileExtension(QString fileExtension)
{
QString appName = QApplication::applicationName();
QString appFilePath = QApplication::applicationFilePath();
// we get the application name and its binary path for the association
QString appName = QApplication::applicationName(); // used for windows registry
QString appFilePath = QApplication::applicationFilePath(); // needed for associating file for opening command
#ifdef WIN32
// WINDOWS ONLY
appFilePath.replace("/", "\\");
......@@ -424,7 +425,23 @@ void ExtensionManager::registerFileExtension(QString fileExtension)
#endif
// TODO : associate file opening on Linux & MacOS
}
// -------------------- promptRegisterFileExtensions --------------------
bool ExtensionManager::promptRegisterFileExtensions(QStringList fileExtensions)
{
// Prompt the user if he wishes those file extension to be associated with this application for default file opening.
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Associate new file extensions for opening."));
msgBox.setText(tr("New component extension(s) allow(s) this application to handle new file type(s) : \n\n")
+ fileExtensions.join(", ") + "\n\n"
+ tr("Do you want this/these file type(s) to be opened by default with this application")
+ " (" + QApplication::applicationName() + ") ?\n");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
return (msgBox.exec() == QMessageBox::Yes);
}
}
......@@ -91,12 +91,17 @@ public:
/// get the list of all the name of the registered Component data directory
static QStringList getDataDirectoryExtNames();
/** Register the file extension with the current application for opening
** This function is called at launch time for registering file extension of component extensions
* This function is called by registerFileExtensions
* @param fileExtension the file extension to associate with the current application for opening
**/
static void registerFileExtension(QString fileExtension);
/// Prompt the user if he wants the current application to natively (by default) open the following file extensions
/// @param fileExtensions The list of file extensions (without the prefixed '.').
/// @return The decision of the user regarding the file association.
static bool promptRegisterFileExtensions(QStringList fileExtensions);
///@}
......@@ -151,6 +156,7 @@ private:
*/
static QMap<QString, ActionExtension*> & getActionExtensionMap();
};
......
......@@ -77,10 +77,10 @@ Application::Application(QString name, int & theArgc, char ** theArgv, bool auto
if (autoloadExtensions) {
ExtensionManager::autoload();
}
// initialize recent/lastUsedDirectory documents from the settings
settings.beginGroup ( name + ".Application" );
// max memorized recent documents
maxRecentDocuments = settings.value( "maxRecentDocuments", 10).toInt();
......@@ -94,7 +94,38 @@ Application::Application(QString name, int & theArgc, char ** theArgv, bool auto
// the last used directory
QDir defaultDir ( Core::getTestDataDir() );
lastUsedDirectory = settings.value ( "lastUsedDirectory", defaultDir.absolutePath() ).toString();
// TODO : remove ifdef WIN32 as soon as we handle file association for other platform than Windows
// see ExtensionManager::registerFileExtension method.
#ifdef WIN32
// File types association with the application for opening
QStringList newFileExtensions;
QStringList fileExtensionsAlreadyRegistered = settings.value("fileExtensionsRegistered").toStringList();
foreach (QString extensionFile, ExtensionManager::getFileExtensions())
{
// check the application can handle new file type
if (!fileExtensionsAlreadyRegistered.contains(extensionFile))
newFileExtensions.append(extensionFile);
}
// check if the application handles new file types
if (!newFileExtensions.isEmpty())
{
// new component extension(s) allow(s) the application to handle new file types
// prompt the user if he wants them to be associated with this application for opening
if (ExtensionManager::promptRegisterFileExtensions(newFileExtensions))
{
// user agrees : register each new file type
foreach (QString fileExtensionToRegister, newFileExtensions)
ExtensionManager::registerFileExtension(fileExtensionToRegister);
}
// save the file types in the application's settings in order not to be prompt again
fileExtensionsAlreadyRegistered.append(newFileExtensions);
settings.setValue("fileExtensionsRegistered", fileExtensionsAlreadyRegistered);
}
#endif
settings.endGroup();
}
......
......@@ -97,7 +97,7 @@ public:
* Use the beginGroup("my area")/endGroup() to define specific settings area.
*
* \note for each beginGroup you use, you HAVE TO use an endGroup(), otherwise the
* settings state integrity is not garanteed!
* settings state integrity is not guaranteed!
*/
static QSettings & getSettings();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment