qBittorrent
cmdoptions.h File Reference
#include <optional>
#include <QString>
#include <QStringList>
#include "base/exceptions.h"
Include dependency graph for cmdoptions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  QBtCommandLineParameters
 
class  CommandLineParameterError
 

Functions

QBtCommandLineParameters parseCommandLine (const QStringList &args)
 
void displayUsage (const QString &prgName)
 

Function Documentation

◆ displayUsage()

void displayUsage ( const QString &  prgName)

Definition at line 582 of file cmdoptions.cpp.

583 {
584 #if defined(Q_OS_WIN) && !defined(DISABLE_GUI)
585  QMessageBox msgBox(QMessageBox::Information, QObject::tr("Help"), makeUsage(prgName), QMessageBox::Ok);
586  msgBox.show(); // Need to be shown or to moveToCenter does not work
587  msgBox.move(Utils::Gui::screenCenter(&msgBox));
588  msgBox.exec();
589 #else
590  printf("%s\n", qUtf8Printable(makeUsage(prgName)));
591 #endif
592 }
QString makeUsage(const QString &prgName)
Definition: cmdoptions.cpp:523
QPoint screenCenter(const QWidget *w)
Definition: utils.cpp:119

References makeUsage(), and Utils::Gui::screenCenter().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseCommandLine()

QBtCommandLineParameters parseCommandLine ( const QStringList &  args)

Definition at line 399 of file cmdoptions.cpp.

400 {
401  QBtCommandLineParameters result {QProcessEnvironment::systemEnvironment()};
402 
403  for (int i = 1; i < args.count(); ++i)
404  {
405  const QString &arg = args[i];
406 
407  if ((arg.startsWith("--") && !arg.endsWith(".torrent"))
408  || (arg.startsWith('-') && (arg.size() == 2)))
409  {
410  // Parse known parameters
411  if (arg == SHOW_HELP_OPTION)
412  {
413  result.showHelp = true;
414  }
415 #if !defined(Q_OS_WIN) || defined(DISABLE_GUI)
416  else if (arg == SHOW_VERSION_OPTION)
417  {
418  result.showVersion = true;
419  }
420 #endif
421  else if (arg == WEBUI_PORT_OPTION)
422  {
423  result.webUiPort = WEBUI_PORT_OPTION.value(arg);
424  if ((result.webUiPort < 1) || (result.webUiPort > 65535))
425  throw CommandLineParameterError(QObject::tr("%1 must specify a valid port (1 to 65535).")
426  .arg(QLatin1String("--webui-port")));
427  }
428 #ifndef DISABLE_GUI
429  else if (arg == NO_SPLASH_OPTION)
430  {
431  result.noSplash = true;
432  }
433 #elif !defined(Q_OS_WIN)
434  else if (arg == DAEMON_OPTION)
435  {
436  result.shouldDaemonize = true;
437  }
438 #endif
439  else if (arg == PROFILE_OPTION)
440  {
441  result.profileDir = PROFILE_OPTION.value(arg);
442  }
443  else if (arg == RELATIVE_FASTRESUME)
444  {
445  result.relativeFastresumePaths = true;
446  }
447  else if (arg == CONFIGURATION_OPTION)
448  {
449  result.configurationName = CONFIGURATION_OPTION.value(arg);
450  }
451  else if (arg == SAVE_PATH_OPTION)
452  {
453  result.savePath = SAVE_PATH_OPTION.value(arg);
454  }
455  else if (arg == PAUSED_OPTION)
456  {
457  result.addPaused = PAUSED_OPTION.value(arg);
458  }
459  else if (arg == SKIP_HASH_CHECK_OPTION)
460  {
461  result.skipChecking = true;
462  }
463  else if (arg == CATEGORY_OPTION)
464  {
465  result.category = CATEGORY_OPTION.value(arg);
466  }
467  else if (arg == SEQUENTIAL_OPTION)
468  {
469  result.sequential = true;
470  }
471  else if (arg == FIRST_AND_LAST_OPTION)
472  {
473  result.firstLastPiecePriority = true;
474  }
475  else if (arg == SKIP_DIALOG_OPTION)
476  {
477  result.skipDialog = SKIP_DIALOG_OPTION.value(arg);
478  }
479  else
480  {
481  // Unknown argument
482  result.unknownParameter = arg;
483  break;
484  }
485  }
486  else
487  {
488  QFileInfo torrentPath;
489  torrentPath.setFile(arg);
490 
491  if (torrentPath.exists())
492  result.torrents += torrentPath.absoluteFilePath();
493  else
494  result.torrents += arg;
495  }
496  }
497 
498  return result;
499 }
std::optional< bool > value(const QString &arg) const
Definition: cmdoptions.cpp:257
constexpr const StringOption CATEGORY_OPTION
Definition: cmdoptions.cpp:333
constexpr const StringOption SAVE_PATH_OPTION
Definition: cmdoptions.cpp:330
constexpr const TriStateBoolOption SKIP_DIALOG_OPTION
Definition: cmdoptions.cpp:336
constexpr const BoolOption NO_SPLASH_OPTION
Definition: cmdoptions.cpp:324
constexpr const BoolOption SHOW_VERSION_OPTION
Definition: cmdoptions.cpp:320
constexpr const BoolOption RELATIVE_FASTRESUME
Definition: cmdoptions.cpp:329
constexpr const StringOption PROFILE_OPTION
Definition: cmdoptions.cpp:327
constexpr const IntOption WEBUI_PORT_OPTION
Definition: cmdoptions.cpp:326
constexpr const BoolOption SEQUENTIAL_OPTION
Definition: cmdoptions.cpp:334
constexpr const BoolOption FIRST_AND_LAST_OPTION
Definition: cmdoptions.cpp:335
constexpr const BoolOption SKIP_HASH_CHECK_OPTION
Definition: cmdoptions.cpp:332
constexpr const BoolOption SHOW_HELP_OPTION
Definition: cmdoptions.cpp:319
constexpr const StringOption CONFIGURATION_OPTION
Definition: cmdoptions.cpp:328
constexpr const TriStateBoolOption PAUSED_OPTION
Definition: cmdoptions.cpp:331
args
Definition: tstool.py:153
QString value(const QString &arg) const
Definition: cmdoptions.cpp:156

References tstool::args, anonymous_namespace{cmdoptions.cpp}::CATEGORY_OPTION, anonymous_namespace{cmdoptions.cpp}::CONFIGURATION_OPTION, anonymous_namespace{cmdoptions.cpp}::FIRST_AND_LAST_OPTION, anonymous_namespace{cmdoptions.cpp}::NO_SPLASH_OPTION, anonymous_namespace{cmdoptions.cpp}::PAUSED_OPTION, anonymous_namespace{cmdoptions.cpp}::PROFILE_OPTION, anonymous_namespace{cmdoptions.cpp}::RELATIVE_FASTRESUME, anonymous_namespace{cmdoptions.cpp}::SAVE_PATH_OPTION, anonymous_namespace{cmdoptions.cpp}::SEQUENTIAL_OPTION, anonymous_namespace{cmdoptions.cpp}::SHOW_HELP_OPTION, anonymous_namespace{cmdoptions.cpp}::SHOW_VERSION_OPTION, anonymous_namespace{cmdoptions.cpp}::SKIP_DIALOG_OPTION, anonymous_namespace{cmdoptions.cpp}::SKIP_HASH_CHECK_OPTION, anonymous_namespace{cmdoptions.cpp}::StringOption::value(), anonymous_namespace{cmdoptions.cpp}::IntOption::value(), anonymous_namespace{cmdoptions.cpp}::TriStateBoolOption::value(), and anonymous_namespace{cmdoptions.cpp}::WEBUI_PORT_OPTION.

Here is the call graph for this function: