ktigcc-1.09-assistant-qt4.diff 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. diff -ur ktigcc/assistant.cpp ktigcc-assistant-qt4/assistant.cpp
  2. --- ktigcc/assistant.cpp 2007-10-09 21:36:50.000000000 +0200
  3. +++ ktigcc-assistant-qt4/assistant.cpp 2008-04-30 03:43:31.000000000 +0200
  4. @@ -32,6 +32,7 @@
  5. #include <qapplication.h>
  6. #include <qeventloop.h>
  7. #include <qtextstream.h>
  8. +#include <qfile.h>
  9. #include <unistd.h>
  10. AssistantClient::AssistantClient(QObject *parent, const QString &profile)
  11. @@ -39,6 +40,12 @@
  12. assistantProfile(profile)
  13. {
  14. if (parent->isWidgetType()) parentWidget=static_cast<QWidget *>(parent);
  15. + if (QFile::exists("/usr/bin/assistant_adp"))
  16. + assistantExecutable="assistant_adp";
  17. + else if (QFile::exists("/usr/bin/assistant-qt4"))
  18. + assistantExecutable="assistant-qt4";
  19. + else
  20. + assistantExecutable="assistant";
  21. }
  22. AssistantClient::~AssistantClient()
  23. @@ -89,7 +96,7 @@
  24. // properly.
  25. procIO->setComm(static_cast<KProcess::Communication>(
  26. KProcess::Stdout|KProcess::MergedStderr));
  27. - (*procIO)<<"assistant"<<"-server";
  28. + (*procIO)<<assistantExecutable<<"-server";
  29. if (!assistantProfile.isNull())
  30. (*procIO)<<"-profile"<<assistantProfile;
  31. if (!page.isNull())
  32. @@ -99,7 +106,7 @@
  33. connect(procIO,SIGNAL(readReady(KProcIO*)),this,SLOT(procIO_readReady()));
  34. if (!procIO->start()) {
  35. KMessageBox::error(parentWidget,"Could not run assistant.\n"
  36. - "This feature requires Qt 3 Assistant.");
  37. + "This feature requires Qt Assistant.");
  38. delete procIO;
  39. procIO=static_cast<KProcIO *>(NULL);
  40. return;
  41. diff -ur ktigcc/assistant.h ktigcc-assistant-qt4/assistant.h
  42. --- ktigcc/assistant.h 2007-10-09 21:36:50.000000000 +0200
  43. +++ ktigcc-assistant-qt4/assistant.h 2008-04-30 03:33:21.000000000 +0200
  44. @@ -41,4 +41,5 @@
  45. KProcIO *procIO;
  46. KExtendedSocket *socket;
  47. QString assistantProfile;
  48. + QString assistantExecutable;
  49. };
  50. diff -ur ktigcc/ktigcc.cpp ktigcc-assistant-qt4/ktigcc.cpp
  51. --- ktigcc/ktigcc.cpp 2007-10-09 03:31:28.000000000 +0200
  52. +++ ktigcc-assistant-qt4/ktigcc.cpp 2008-06-06 02:56:10.000000000 +0200
  53. @@ -21,10 +21,12 @@
  54. #include <cstdio>
  55. #include <cstdlib>
  56. +#include <cstring>
  57. #include <unistd.h>
  58. #include <qstring.h>
  59. #include <qimage.h>
  60. #include <qdir.h>
  61. +#include <qfile.h>
  62. #include <kapplication.h>
  63. #include <kcmdlineargs.h>
  64. #include <kaboutdata.h>
  65. @@ -37,6 +39,7 @@
  66. #include <kconfig.h>
  67. #include <glib.h>
  68. #include "mainform.h"
  69. +#include "tpr.h"
  70. // Check for KDE version at compile time to avoid wasting users' time
  71. #if KDE_VERSION < KDE_MAKE_VERSION(3,5,7)
  72. @@ -227,7 +230,40 @@
  73. void force_qt_assistant_page(int n)
  74. {
  75. - QString fname=QDir::homeDirPath()+"/.qt/qt_assistantrc";
  76. + bool useQt4=(QFile::exists("/usr/bin/assistant_adp") || QFile::exists("/usr/bin/assistant-qt4"));
  77. + QString fname=QDir::homeDirPath()+(useQt4?"/.config/Trolltech/Assistant.conf":"/.qt/qt_assistantrc");
  78. + mkdir_multi(fname);
  79. + char qtVersion[5]="3.3";
  80. + size_t verlen=3;
  81. + if (useQt4) {
  82. + QStringList entries;
  83. + QDir libdir("/usr/lib64");
  84. + if (libdir.exists()) {
  85. + entries=libdir.entryList("libQtCore.so.4.?");
  86. + if (entries.empty()) entries=libdir.entryList("libQtCore.so.4.??");
  87. + }
  88. + if (entries.empty()) {
  89. + libdir.cd("/usr/lib");
  90. + if (libdir.exists()) {
  91. + entries=libdir.entryList("libQtCore.so.4.?");
  92. + if (entries.empty()) entries=libdir.entryList("libQtCore.so.4.??");
  93. + }
  94. + }
  95. + if (entries.empty()) {
  96. + qWarning("Failed to determine Qt 4 version");
  97. + return;
  98. + }
  99. + QString soname=entries.first();
  100. + unsigned l=soname.length();
  101. + *qtVersion='4';
  102. + if (soname[l-2]=='.')
  103. + qtVersion[2]=soname[l-1].latin1();
  104. + else {
  105. + qtVersion[2]=soname[l-2].latin1();
  106. + qtVersion[3]=soname[l-1].latin1();
  107. + verlen++;
  108. + }
  109. + }
  110. FILE *f=fopen(fname,"r+b");
  111. if (!f) f=fopen(fname,"w+b");
  112. if (!f) exit(1);
  113. @@ -237,13 +273,21 @@
  114. char buffer[flen+1];
  115. memset(buffer,0,flen+1);
  116. if (fread(buffer,1,flen,f)<flen) exit(1);
  117. - char *p=strstr(buffer,"SideBarPage=");
  118. - if (p) {
  119. - fseek(f,p-buffer+12,SEEK_SET);
  120. - fputc('0'+n,f);
  121. - } else {
  122. + char *p=strtok(buffer,"\n");
  123. + bool wantedSection=false, found=false;
  124. + while (p) {
  125. + if (*p=='[')
  126. + wantedSection=(!strncmp(p+1,qtVersion,verlen) && p[verlen+1]==']' && !p[verlen+2]);
  127. + else if (wantedSection && !strncmp(p,"SideBarPage=",12)) {
  128. + fseek(f,p-buffer+12,SEEK_SET);
  129. + fputc('0'+n,f);
  130. + found=true;
  131. + }
  132. + p=strtok(NULL,"\n");
  133. + }
  134. + if (!found) {
  135. fseek(f,0,SEEK_END);
  136. - fprintf(f,"\n\n[3.3]\nSideBarPage=%d\n",n);
  137. + fprintf(f,"\n\n[%s]\nSideBarPage=%d\n",qtVersion,n);
  138. }
  139. fclose(f);
  140. }