PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/installwindow.cpp

http://kludgets.googlecode.com/
C++ | 204 lines | 151 code | 43 blank | 10 comment | 7 complexity | a1a9f7c99050625d9224c8ff011177ca MD5 | raw file
Possible License(s): LGPL-3.0
  1. #include "installwindow.h"
  2. #include "ksettings.h"
  3. #include "kdocument.h"
  4. #include "kapp.h"
  5. #include "kutil.h"
  6. #include <QWebView>
  7. #include <QWebFrame>
  8. #include <QDesktopWidget>
  9. #include <QApplication>
  10. InstallWindow::InstallWindow(const KludgetInfo& i) :
  11. PreferenceWindow(0),
  12. info(i),
  13. view(new QWebView)
  14. {
  15. settings = new KSettings(this);
  16. settings->setPath(info.storagePath + "/access.xml");
  17. }
  18. void InstallWindow::createHeader()
  19. {
  20. view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
  21. view->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
  22. KDocument about;
  23. about.openDocument(info.configFile);
  24. QString iconPath = info.path + "/icon.png";
  25. if (QFile::exists(iconPath))
  26. about.setValue("widget/icon", iconPath);
  27. else
  28. about.setValue("widget/icon", "package.png");
  29. about.transform(":resources/xsl/aboutWidget.xsl");
  30. view->setHtml(about.toString(), QUrl::fromLocalFile(QApplication::applicationDirPath() + "/widgets/resources/"));
  31. layout->addWidget(view);
  32. /*
  33. QString url = about.getValue("widget/about/url","");
  34. if (url != "")
  35. QDesktopServices::openUrl(QUrl(url));
  36. */
  37. QPalette pal = palette();
  38. pal.setBrush(QPalette::Background, Qt::white);
  39. setPalette(pal);
  40. view->setFixedHeight(150);
  41. }
  42. void InstallWindow::onUpdate()
  43. {}
  44. void InstallWindow::createDialogControls()
  45. {
  46. toolbar->setVisible(false);
  47. QHBoxLayout *h = new QHBoxLayout();
  48. QPushButton *save, *cancel;
  49. layout->addLayout(h);
  50. h->setContentsMargins(16, 16, 16, 8);
  51. h->addSpacing(240);
  52. h->addWidget(save = new QPushButton("Install"));
  53. h->addWidget(cancel = new QPushButton("Cancel"));
  54. // save
  55. connect(save, SIGNAL(clicked()), this, SLOT(onSave()));
  56. connect(save, SIGNAL(clicked()), this, SLOT(close()));
  57. // cancel
  58. connect(cancel, SIGNAL(clicked()), this, SLOT(onCancel()));
  59. }
  60. AboutWindow::AboutWindow(const KludgetInfo& info) :
  61. InstallWindow(info)
  62. {}
  63. void AboutWindow::createDialogControls()
  64. {
  65. PreferenceTab *w = prefTabMap.value("package");
  66. if (w)
  67. w->hide();
  68. toolbar->setVisible(false);
  69. QHBoxLayout *h = new QHBoxLayout();
  70. QPushButton *security, *ok, *save, *cancel;
  71. layout->addLayout(h);
  72. h->setContentsMargins(16, 16, 16, 8);
  73. h->addWidget(security = new QPushButton("Security"));
  74. h->addSpacing(300);
  75. h->addWidget(ok = new QPushButton("Ok"));
  76. h->addWidget(save = new QPushButton("Save"));
  77. h->addWidget(cancel = new QPushButton("Cancel"));
  78. // save
  79. connect(security, SIGNAL(clicked()), this, SLOT(onSecurity()));
  80. connect(ok, SIGNAL(clicked()), this, SLOT(close()));
  81. connect(save, SIGNAL(clicked()), this, SLOT(onSave()));
  82. connect(save, SIGNAL(clicked()), this, SLOT(close()));
  83. connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
  84. security->setObjectName("security");
  85. ok->setObjectName("ok");
  86. save->setObjectName("save");
  87. save->hide();
  88. cancel->setObjectName("cancel");
  89. cancel->hide();
  90. security->setFixedWidth(100);
  91. save->setFixedWidth(100);
  92. ok->setFixedWidth(100);
  93. cancel->setFixedWidth(100);
  94. adjustSize();
  95. }
  96. void AboutWindow::onSecurity()
  97. {
  98. PreferenceTab *w = prefTabMap.value("package");
  99. if (w)
  100. w->show();
  101. QPushButton *btn = 0;
  102. btn = findChild<QPushButton*>("security");
  103. if (btn)
  104. btn->hide();
  105. btn = findChild<QPushButton*>("ok");
  106. if (btn)
  107. btn->hide();
  108. btn = findChild<QPushButton*>("save");
  109. if (btn)
  110. btn->show();
  111. btn = findChild<QPushButton*>("cancel");
  112. if (btn)
  113. btn->show();
  114. adjustSize();
  115. }
  116. AboutKludgetWindow::AboutKludgetWindow()
  117. : PreferenceWindow(0),
  118. view(new QWebView)
  119. {}
  120. void AboutKludgetWindow::createHeader()
  121. {
  122. //setWindowIcon(QIcon(":resources/images/kludget.png"));
  123. view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
  124. view->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
  125. KDocument about;
  126. about.setValue("widget/name", "Kludget Engine");
  127. about.setValue("widget/version", KApp::version());
  128. about.setValue("widget/userAgent", KApp::userAgent());
  129. about.setValue("widget/logo", "kludget.png");
  130. about.setValue("widget/icon", "engine.png");
  131. about.transform(":resources/xsl/aboutKludget.xsl");
  132. view->setHtml(about.toString(), QUrl::fromLocalFile(QApplication::applicationDirPath() + "/widgets/resources/"));
  133. layout->addWidget(view);
  134. QPalette pal = palette();
  135. pal.setBrush(QPalette::Background, Qt::white);
  136. setPalette(pal);
  137. view->setFixedHeight(240);
  138. }
  139. void AboutKludgetWindow::createDialogControls()
  140. {
  141. QHBoxLayout *h = new QHBoxLayout();
  142. QPushButton *credits, *site, *close;
  143. layout->addLayout(h);
  144. h->setContentsMargins(16, 16, 16, 8);
  145. h->addWidget(site = new QPushButton("Visit Website"));
  146. h->addWidget(credits = new QPushButton("Credits"));
  147. h->addSpacing(300);
  148. h->addWidget(close = new QPushButton("Ok"));
  149. // save
  150. connect(site, SIGNAL(clicked()), this, SLOT(onWebSite()));
  151. connect(credits, SIGNAL(clicked()), this, SLOT(onCredits()));
  152. connect(close, SIGNAL(clicked()), this, SLOT(close()));
  153. }
  154. void AboutKludgetWindow::onWebSite()
  155. {
  156. QDesktopServices::openUrl(QUrl("http://www.kludgets.com/download"));
  157. }
  158. void AboutKludgetWindow::onCredits()
  159. {
  160. QDesktopServices::openUrl(QUrl("http://code.google.com/p/kludgets/wiki/Credits"));
  161. }