/gui/src/forms/frmopensubtitlesconfig.cpp

https://github.com/QNapi/qnapi · C++ · 55 lines · 31 code · 11 blank · 13 comment · 1 complexity · 920c60a5a9319f21aebf272ed5691355 MD5 · raw file

  1. /*****************************************************************************
  2. ** QNapi
  3. ** Copyright (C) 2008-2017 Piotr Krzemiński <pio.krzeminski@gmail.com>
  4. **
  5. ** This program is free software; you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation; either version 2 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  11. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  12. **
  13. *****************************************************************************/
  14. #include <QDesktopServices>
  15. #include <QDesktopWidget>
  16. #include "engines/opensubtitlesdownloadengine.h"
  17. #include "frmopensubtitlesconfig.h"
  18. frmOpenSubtitlesConfig::frmOpenSubtitlesConfig(const EngineConfig &config,
  19. QWidget *parent,
  20. Qt::WindowFlags f)
  21. : QDialog(parent, f), config(config) {
  22. ui.setupUi(this);
  23. ui.leNick->setText(config.nick());
  24. ui.lePass->setText(config.password());
  25. QIcon openSubtitlesIcon =
  26. QIcon(QPixmap(OpenSubtitlesDownloadEngine::pixmapData));
  27. setWindowIcon(openSubtitlesIcon);
  28. connect(ui.pbRegister, SIGNAL(clicked()), this, SLOT(pbRegisterClicked()));
  29. QRect position = frameGeometry();
  30. position.moveCenter(QDesktopWidget().availableGeometry().center());
  31. move(position.topLeft());
  32. }
  33. EngineConfig frmOpenSubtitlesConfig::getConfig() const { return config; }
  34. void frmOpenSubtitlesConfig::accept() {
  35. config = config.setNick(ui.leNick->text()).setPassword(ui.lePass->text());
  36. QDialog::accept();
  37. }
  38. void frmOpenSubtitlesConfig::pbRegisterClicked() {
  39. Maybe<QUrl> maybeRegistrationUrl =
  40. OpenSubtitlesDownloadEngine::metadata.registrationUrl();
  41. if (maybeRegistrationUrl) {
  42. QDesktopServices::openUrl(maybeRegistrationUrl.value());
  43. }
  44. }