/[svn]/qsampler/trunk/src/qsamplerOptions.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerOptions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1803 by schoenebeck, Sun Dec 7 13:58:16 2008 UTC revision 2077 by capela, Wed Mar 31 09:07:30 2010 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 44  namespace QSampler { Line 44  namespace QSampler {
44  Options::Options (void)  Options::Options (void)
45          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
46  {  {
47            loadOptions();
48    }
49    
50    
51    // Default Destructor.
52    Options::~Options (void)
53    {
54            saveOptions();
55    }
56    
57    
58    // Explicit load method.
59    void Options::loadOptions (void)
60    {
61          // Begin into general options group.          // Begin into general options group.
62          m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
63    
# Line 140  Options::Options (void) Line 154  Options::Options (void)
154  }  }
155    
156    
157  // Default Destructor.  // Explicit save method.
158  Options::~Options (void)  void Options::saveOptions (void)
159  {  {
160          // Make program version available in the future.          // Make program version available in the future.
161          m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
# Line 225  Options::~Options (void) Line 239  Options::~Options (void)
239          m_settings.setValue("/Volume", iVolume);          m_settings.setValue("/Volume", iVolume);
240          m_settings.setValue("/Loadmode", iLoadMode);          m_settings.setValue("/Loadmode", iLoadMode);
241          m_settings.endGroup();          m_settings.endGroup();
242    
243            // Save/commit to disk.
244            m_settings.sync();
245  }  }
246    
247    
248  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
249  // Settings accessor.  // Settings accessor.
250  //  //
# Line 242  QSettings& Options::settings (void) Line 260  QSettings& Options::settings (void)
260  //  //
261    
262  // Help about command line options.  // Help about command line options.
263  void Options::print_usage ( const char *arg0 )  void Options::print_usage ( const QString& arg0 )
264  {  {
265          QTextStream out(stderr);          QTextStream out(stderr);
266          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
# Line 258  void Options::print_usage ( const char * Line 276  void Options::print_usage ( const char *
276    
277    
278  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
279  bool Options::parse_args ( int argc, char **argv )  bool Options::parse_args ( const QStringList& args )
280  {  {
281          QTextStream out(stderr);          QTextStream out(stderr);
282          const QString sEol = "\n\n";          const QString sEol = "\n\n";
283          int iCmdArgs = 0;          int iCmdArgs = 0;
284            int argc = args.count();
285    
286          for (int i = 1; i < argc; i++) {          for (int i = 1; i < argc; i++) {
287    
288                  if (iCmdArgs > 0) {                  if (iCmdArgs > 0) {
289                          sSessionFile += " ";                          sSessionFile += " ";
290                          sSessionFile += argv[i];                          sSessionFile += args.at(i);
291                          iCmdArgs++;                          iCmdArgs++;
292                          continue;                          continue;
293                  }                  }
294    
295                  QString sArg = argv[i];                  QString sArg = args.at(i);
296                  QString sVal = QString::null;                  QString sVal = QString::null;
297                  int iEqual = sArg.indexOf("=");                  int iEqual = sArg.indexOf("=");
298                  if (iEqual >= 0) {                  if (iEqual >= 0) {
299                          sVal = sArg.right(sArg.length() - iEqual - 1);                          sVal = sArg.right(sArg.length() - iEqual - 1);
300                          sArg = sArg.left(iEqual);                          sArg = sArg.left(iEqual);
301                  }                  }
302                  else if (i < argc)                  else if (i < argc - 1)
303                          sVal = argv[i + 1];                          sVal = args.at(i + 1);
304    
305                  if (sArg == "-s" || sArg == "--start") {                  if (sArg == "-s" || sArg == "--start") {
306                          bServerStart = true;                          bServerStart = true;
# Line 305  bool Options::parse_args ( int argc, cha Line 324  bool Options::parse_args ( int argc, cha
324                                  i++;                                  i++;
325                  }                  }
326                  else if (sArg == "-?" || sArg == "--help") {                  else if (sArg == "-?" || sArg == "--help") {
327                          print_usage(argv[0]);                          print_usage(args.at(0));
328                          return false;                          return false;
329                  }                  }
330                  else if (sArg == "-v" || sArg == "--version") {                  else if (sArg == "-v" || sArg == "--version") {
# Line 337  bool Options::parse_args ( int argc, cha Line 356  bool Options::parse_args ( int argc, cha
356  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
357  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
358    
359  void Options::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget, bool bVisible )
360  {  {
361          // Try to restore old form window positioning.          // Try to restore old form window positioning.
362          if (pWidget) {          if (pWidget) {
363                  QPoint fpos;                  QPoint wpos;
364                  QSize  fsize;                  QSize  wsize;
                 bool bVisible;  
365                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
366                  fpos.setX(m_settings.value("/x", -1).toInt());                  wpos.setX(m_settings.value("/x", -1).toInt());
367                  fpos.setY(m_settings.value("/y", -1).toInt());                  wpos.setY(m_settings.value("/y", -1).toInt());
368                  fsize.setWidth(m_settings.value("/width", -1).toInt());                  wsize.setWidth(m_settings.value("/width", -1).toInt());
369                  fsize.setHeight(m_settings.value("/height", -1).toInt());                  wsize.setHeight(m_settings.value("/height", -1).toInt());
370                  bVisible = m_settings.value("/visible", false).toBool();                  if (!bVisible) bVisible = m_settings.value("/visible", false).toBool();
371                  m_settings.endGroup();                  m_settings.endGroup();
372                  if (fpos.x() > 0 && fpos.y() > 0)                  if (wpos.x() > 0 && wpos.y() > 0)
373                          pWidget->move(fpos);                          pWidget->move(wpos);
374                  if (fsize.width() > 0 && fsize.height() > 0)                  if (wsize.width() > 0 && wsize.height() > 0)
375                          pWidget->resize(fsize);                          pWidget->resize(wsize);
376                  else          //      else
377                          pWidget->adjustSize();          //              pWidget->adjustSize();
378                  if (bVisible)                  if (bVisible)
379                          pWidget->show();                          pWidget->show();
380                  else          //      else
381                          pWidget->hide();          //              pWidget->hide();
382          }          }
383  }  }
384    
385    
386  void Options::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget, bool bVisible )
387  {  {
388          // Try to save form window position...          // Try to save form window position...
389          // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
390          // only save the form geometry while its up and visible)          // only save the form geometry while its up and visible)
391          if (pWidget) {          if (pWidget) {
392                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
393                  bool bVisible = pWidget->isVisible();                  const QPoint& wpos  = pWidget->pos();
394                  const QPoint& fpos  = pWidget->pos();                  const QSize&  wsize = pWidget->size();
395                  const QSize&  fsize = pWidget->size();                  if (!bVisible) bVisible = pWidget->isVisible();
396                  m_settings.setValue("/x", fpos.x());                  m_settings.setValue("/x", wpos.x());
397                  m_settings.setValue("/y", fpos.y());                  m_settings.setValue("/y", wpos.y());
398                  m_settings.setValue("/width", fsize.width());                  m_settings.setValue("/width", wsize.width());
399                  m_settings.setValue("/height", fsize.height());                  m_settings.setValue("/height", wsize.height());
400                  m_settings.setValue("/visible", bVisible);                  m_settings.setValue("/visible", bVisible);
401                  m_settings.endGroup();                  m_settings.endGroup();
402          }          }

Legend:
Removed from v.1803  
changed lines
  Added in v.2077

  ViewVC Help
Powered by ViewVC