Logo Search packages:      
Sourcecode: massxpert version File versions

bool massXpert::ConfigSettings::initializeSystemConfig (  ) 

Initializes the members of the class.

The initialization of the members of the class involves determining where the system and user configuration directories are located.

  • System configuration directory: it is set by the variable MASSXPERT_DATA_DIR in the config.h file. Thus, this directory is set at compile time.
  • User configuration directory: it is determined at run time by inspecting the value returned by the call to QDir::homePath (). Under Windows this function will return the directory of the current user's profile. Typically, this is: "C:\Documents and Settings\Username". Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath() function is used(this latter function returns '/' on non-Windows systems and "c:\\" on Windows).
Inside the User/System configuration directories a "pol-chem-defs" directory will contain a number of files:

  • massxpert-pol-chem-defs-cat is a catalogue that relates polymer chemistry definition names with the corresponding directories where the definition data are to be found. For example, one line from that file might be:
protein=/home/rusconi/.massxpert/pol-chem-defs/protein/protein.xml

This line tells that the "protein" polymer chemistry definition file is named protein.xml and that it is located, along with all the other data files pertaining to that same polymer chemistry definition, in the /home/rusconi/.massxpert/pol-chem-defs/protein directory.

During initialization, if system configuration directories are not found, then these are not created. Which is not the case for the user configuration directories: if these are not found, they are created, thus yielding ---on a UNIX-like system for example--- the following directories:

$HOME/.massxpert and $HOME/.massxpert/pol-chem-defs

The user might then populate these directories with data suiting her needs.

Returns:
true if initialization was successful, false otherwise.

Definition at line 104 of file configSettings.cpp.

References m_systemDataDir, m_systemLocalizationDir, m_systemPluginDir, and m_systemPolChemDefCatDir.

  {
    QDir dir;

    // First off, some general concepts.

    // When the software is built, a configuration process will
    // provide values for a number of #defined variables, depending on
    // the platform on which the software is built.

    // For example on MS-Windows, the following variables are defined:

    /*
      #define MASSXPERT_BIN_DIR C:/Program Files/massxpert
      #define MASSXPERT_DATA_DIR C:/Program Files/massxpert/data
      #define MASSXPERT_PLUGIN_DIR C:/Program Files/massxpert/plugins
      #define MASSXPERT_LOCALE_DIR C:/Program Files/massxpert/locales
      #define MASSXPERT_USERMAN_DIR C:/Program Files/massxpert/doc/usermanual
    
    */

    // On GNU/Linux, instead, the following variables are defined:

    /*
      #define MASSXPERT_BIN_DIR /usr/local/bin
      #define MASSXPERT_DATA_DIR /usr/local/share/massxpert
      #define MASSXPERT_PLUGIN_DIR /usr/local/lib/massxpert/plugins
      #define MASSXPERT_LOCALE_DIR /usr/local/share/massxpert/locales
      #define MASSXPERT_USERMAN_DIR: /usr/local/share/doc/massxpert/usermanual
    */

    /* On Mac OS X, instead, the software is built using not cmake,
       but qmake, and that makes it buildable using Xcode. The build
       generates in this case a Mac Bundle massXpert.app, which
       installs anywhere as long as its internal structure is
       conserved. There is an API to identify from which location the
       bundle is used(double-clicking onto the massXpert.app
       icon). We use that API to get the bundle directory, which might
       be something like /Applications/massXpert.app if the bundle was
       dropped into /Applications.
    */

#if defined(Q_WS_MAC)
    CFURLRef bundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    
    CFStringRef macPath = 
      CFURLCopyFileSystemPath(bundleRef, kCFURLPOSIXPathStyle);
    
    QString bundleDir = 
      CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());
    
    CFRelease(bundleRef);
    CFRelease(macPath);
#endif


    // Now, it might be of interest for the user to install the
    // software in another location than the canonical one. In this
    // case, the program should still be able to access the data.

    // This is what this function is for. This function will try to
    // establish if the data that were built along the software
    // package are actually located in the cnaonical places listed
    // above. If not, this function returns false. The caller might
    // then take actions to let the user manually instruct the program
    // of where the data are located.

    // All this procedure is setup so as to let the user install the
    // software wherever she wants.


      /////////////////// MASSXPERT_DATA_DIR ///////////////////
      /////////////////// MASSXPERT_DATA_DIR ///////////////////
      /////////////////// MASSXPERT_DATA_DIR ///////////////////
    
#ifdef Q_WS_MAC
    dir.setPath(bundleDir + QDir::separator() + "Contents" +
             QDir::separator() + "Resources" +
             QDir::separator() + "data");
#else
    dir.setPath(QString(MASSXPERT_DATA_DIR));
#endif

    // The path must be absolute and must exist.

    if (!dir.isAbsolute())
      return false;
    
    if (!dir.exists())
      return false;

    m_systemDataDir = dir.absolutePath();
    
    // OK, the directory exists, we still have to make sure that we
    // can find the proper data in it. Namely the directory where the
    // data are acutally stored(pol-chem-defs subdirectory).

    dir.setPath(dir.absolutePath() + 
             QDir::separator() + "pol-chem-defs");
    
    if (!dir.exists())
      return false;

    m_systemPolChemDefCatDir = dir.absolutePath();

    // Finally, make sure the system catalogue file of all the polymer
    // chemistry definitions shipped in the program package, that sits
    // in the "pol-chem-defs" directory.

    QString filePath = dir.absolutePath() +
      QDir::separator() + "massxpert-pol-chem-defs-cat";
    
    if (!QFile::exists(filePath))
      return false;
    

      /////////////////// MASSXPERT_PLUGIN_DIR ///////////////////
      /////////////////// MASSXPERT_PLUGIN_DIR ///////////////////
      /////////////////// MASSXPERT_PLUGIN_DIR ///////////////////

#ifdef Q_WS_MAC
    dir.setPath(bundleDir + QDir::separator() + "Contents" +
             QDir::separator() + "Plugins");
#else
    dir.setPath(QString(MASSXPERT_PLUGIN_DIR));
#endif
    
    // The path must be absolute and must exist.
    
    if (!dir.isAbsolute())
      return false;
    
    if (!dir.exists())
      return false;
    
    // At the moment there are three plugins:

    // libnumeralsLocaleConverterPlugin.so 
    
    // libmassListSorterPlugin.so
    
    // libseqToolsPlugin.so
    
    QString libname;
    
#ifdef Q_OS_LINUX
    libname = "libnumeralsLocaleConverterPlugin.so";
#elif defined Q_OS_DARWIN
    libname = "libnumeralsLocaleConverterPlugin.dylib";
#elif defined Q_OS_WIN32
    libname ="libnumeralsLocaleConverterPlugin.dll";
#endif
    
    filePath = QString(dir.absolutePath() +
                  QDir::separator() +
                  libname);
    
    // But in fact, we cannot assume that there are plugins.
    //    if (!QFile::exists(filePath))
    //  return false;

    m_systemPluginDir = dir.absolutePath();
    

      /////////////////// MASSXPERT_LOCALE_DIR ///////////////////
      /////////////////// MASSXPERT_LOCALE_DIR ///////////////////
      /////////////////// MASSXPERT_LOCALE_DIR ///////////////////

#ifdef Q_WS_MAC
    dir.setPath(bundleDir + QDir::separator() + "Contents" +
             QDir::separator() + "Locales");
#else
    dir.setPath(QString(MASSXPERT_LOCALE_DIR));
#endif
    
    // The path must be absolute and must exist.

    if (!dir.isAbsolute())
      return false;
    
    if (!dir.exists())
      return false;
    
    // At the moment there is the french translation: massxpert_fr.qm
    
    filePath = QString(dir.absolutePath() +
                  QDir::separator() +
                  "massxpert_fr.qm");
    
    if (!QFile::exists(filePath))
      return false;
    
    m_systemLocalizationDir = dir.absolutePath();
    return true;
  }


Generated by  Doxygen 1.6.0   Back to index