newsdlg.ui.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /****************************************************************************
  2. ** ui.h extension file, included from the uic-generated form implementation.
  3. **
  4. ** If you want to add, delete, or rename functions or slots, use
  5. ** Qt Designer to update this file, preserving your code.
  6. **
  7. ** You should not define a constructor or destructor in this file.
  8. ** Instead, write your code in functions called init() and destroy().
  9. ** These will automatically be called by the form's constructor and
  10. ** destructor.
  11. *****************************************************************************/
  12. /*
  13. ktigcc - TIGCC IDE for KDE
  14. Copyright (C) 2006 Kevin Kofler
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2, or (at your option)
  18. any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software Foundation,
  25. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #include <kcmultidialog.h>
  28. #include <kcmoduleinfo.h>
  29. #include <krun.h>
  30. #include <kurl.h>
  31. #include <kio/netaccess.h>
  32. #include <kmessagebox.h>
  33. #include <qdatetime.h>
  34. #include <qstring.h>
  35. #include <qlistbox.h>
  36. #include <qcolor.h>
  37. #include <qpainter.h>
  38. #include <qpen.h>
  39. #include <cstdio>
  40. #include <cstring>
  41. #include "ktigcc.h"
  42. class ColoredListBoxText : public QListBoxText {
  43. public:
  44. ColoredListBoxText(QListBox *listbox, const QString &text,
  45. const QColor &textColor)
  46. : QListBoxText(listbox,text), color(textColor) {}
  47. virtual ~ColoredListBoxText() {}
  48. protected:
  49. virtual void paint(QPainter *painter) {
  50. QPen oldPen=painter->pen();
  51. QPen pen=oldPen;
  52. pen.setColor(color);
  53. painter->setPen(pen);
  54. QListBoxText::paint(painter);
  55. painter->setPen(oldPen);
  56. }
  57. private:
  58. QColor color;
  59. };
  60. // This hack overrides the comment so it doesn't get translated while
  61. // everything else doesn't.
  62. class ProxyModuleInfo : public KCModuleInfo {
  63. public:
  64. ProxyModuleInfo() : KCModuleInfo("proxy") {
  65. setComment("Configure the proxy servers used");
  66. }
  67. };
  68. bool NewsDialog::loadNews()
  69. {
  70. QString tmpFile;
  71. bool result=FALSE;
  72. pconfig->setGroup("News Headlines");
  73. QDateTime defaultDateTime;
  74. QDate latestHeadline=pconfig->readDateTimeEntry("Latest Headline",
  75. &defaultDateTime).date();
  76. if(KIO::NetAccess::download(
  77. KURL("http://tigcc.ticalc.org/linux/newsheadlines.txt"),tmpFile,this)) {
  78. #define ERROR(s) do {KMessageBox::error(this,(s)); goto done;} while(0)
  79. #define ZAP_LF() do {char *p=line+(std::strlen(line)-1); if (*p=='\n') *p=0;} while(0)
  80. #define ZAP_CR() do {char *p=line+(std::strlen(line)-1); if (*p=='\r') *p=0;} while(0)
  81. std::FILE *f=std::fopen(tmpFile,"r");
  82. if (!f) ERROR("Downloading news failed.");
  83. char line[32768];
  84. // "TIGCC News Format"
  85. if (!std::fgets(line,32768,f)) ERROR("Invalid news file.");
  86. ZAP_LF();ZAP_CR();
  87. if (std::strcmp(line,"TIGCC News Format")) ERROR("Invalid news file.");
  88. // Empty line
  89. if (!std::fgets(line,32768,f)) ERROR("Invalid news file.");
  90. ZAP_LF();ZAP_CR();
  91. if (*line) ERROR("Invalid news file.");
  92. newsListBox->clear();
  93. while (1) {
  94. bool itemIsNew=FALSE;
  95. unsigned y,m,d;
  96. // Date
  97. if (!std::fgets(line,32768,f)) goto done;
  98. ZAP_LF();ZAP_CR();
  99. if (!*line) goto done;
  100. if (std::sscanf(line,"%4u%2u%2u",&y,&m,&d)<3) ERROR("Invalid news file.");
  101. if (latestHeadline.isNull() || QDate(y,m,d)>latestHeadline) {
  102. if (!result) {
  103. pconfig->writeEntry("Latest Headline",QDateTime(QDate(y,m,d)));
  104. pconfig->sync();
  105. }
  106. result=itemIsNew=TRUE;
  107. }
  108. // Title
  109. if (!std::fgets(line,32768,f)) ERROR("Invalid news file.");
  110. ZAP_LF();ZAP_CR();
  111. new ColoredListBoxText(newsListBox,QString::fromUtf8(line),
  112. itemIsNew?Qt::red:Qt::gray);
  113. // Empty line
  114. if (!std::fgets(line,32768,f)) goto done;
  115. ZAP_LF();ZAP_CR();
  116. if (*line) ERROR("Invalid news file.");
  117. }
  118. #undef ERROR
  119. #undef ZAP_LF
  120. #undef ZAP_CR
  121. done: if (f) std::fclose(f);
  122. KIO::NetAccess::removeTempFile(tmpFile);
  123. } else {
  124. KMessageBox::error(this,KIO::NetAccess::lastErrorString());
  125. }
  126. return result;
  127. }
  128. void NewsDialog::proxySettingsButton_clicked()
  129. {
  130. ProxyModuleInfo proxyModuleInfo;
  131. if (proxyModuleInfo.moduleName().isNull())
  132. KMessageBox::error(this,"This feature requires kdebase.");
  133. else {
  134. KCMultiDialog proxySettings(this);
  135. proxySettings.addModule(proxyModuleInfo);
  136. proxySettings.exec();
  137. }
  138. }
  139. void NewsDialog::refreshButton_clicked()
  140. {
  141. loadNews();
  142. }
  143. void NewsDialog::visitButton_clicked()
  144. {
  145. KRun::runURL(KURL("http://tigcc.ticalc.org/linux/"),"text/html");
  146. }