kwhatsthismanager.cpp
00001 /* This file is part of the KDE Libraries 00002 * Copyright (C) 2004 Peter Rockai (mornfall) <mornfall@danill.sk> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 #include "kwhatsthismanager_p.h" 00020 #include "tqwhatsthis.h" 00021 #include <tqvariant.h> 00022 #include <kdebug.h> 00023 #include <tqtextedit.h> 00024 #include <tdelocale.h> 00025 #include <tdeapplication.h> 00026 00027 KWhatsThisManager *KWhatsThisManager::s_instance = 0; 00028 00029 class KWhatsThisUndefined : public TQWhatsThis 00030 { 00031 public: 00032 KWhatsThisUndefined (TQWidget *); 00033 TQString text (const TQPoint &); 00034 public slots: 00035 bool clicked (const TQString &); 00036 protected: 00037 TQWidget *m_widget; 00038 }; 00039 00040 KWhatsThisUndefined::KWhatsThisUndefined (TQWidget *w) 00041 : TQWhatsThis (w) 00042 { 00043 m_widget = w; 00044 } 00045 00046 TQString KWhatsThisUndefined::text (const TQPoint &) 00047 { 00048 if (!m_widget) 00049 return ""; 00050 TQString txt = i18n ("<b>Not Defined</b><br>There is no \"What's This?\"" 00051 " help assigned to this widget. If you want to help us to " 00052 " describe the widget, you are welcome to <a href=\"submit" 00053 "-whatsthis\">send us your own \"What's This?\" help</a> for it."); 00054 TQString parent; 00055 if (m_widget -> parentWidget ()) 00056 parent = TQWhatsThis::textFor (m_widget -> parentWidget ()); 00057 if (parent != txt) 00058 if (! parent . isEmpty ()) 00059 return parent; 00060 return txt; 00061 } 00062 00063 bool KWhatsThisUndefined::clicked (const TQString& href) 00064 { 00065 if (href == "submit-whatsthis") { 00066 TQWidget *w = m_widget; 00067 TQString body; 00068 body . append ("Widget text: '" + (m_widget -> property ("text") . toString ()) + "'\n"); 00069 TQString dsc = TQString ("current --> ") + m_widget -> name (); 00070 dsc . append (TQString (" (") + m_widget -> className () + ")\n"); 00071 for (w = m_widget; w && w != m_widget -> topLevelWidget (); w = w -> parentWidget ()) { 00072 dsc . append (w -> name ()); 00073 dsc . append (TQString (" (") + w -> className () + ")\n"); 00074 } 00075 w = m_widget -> topLevelWidget (); 00076 if (w) { 00077 dsc . append ("toplevel --> "); 00078 dsc . append (w -> name ()); 00079 dsc . append (TQString (" (") + w -> className () + ")\n"); 00080 } 00081 body . append (dsc); 00082 TQString subj ("What's This submission: "); 00083 subj . append (tqApp -> argv () [0]); 00084 body . append ("\nPlease type in your what's this help between these lines: " 00085 "\n--%-----------------------------------------------------------------------\n" 00086 "\n--%-----------------------------------------------------------------------"); 00087 kapp -> invokeMailer ("quality-whatsthis@kde.org", "", "", subj, body); 00088 } 00089 return TRUE; 00090 } 00091 00092 void KWhatsThisManager::init () 00093 { 00094 if (s_instance) 00095 return; 00096 s_instance = new KWhatsThisManager; 00097 } 00098 00099 KWhatsThisManager::KWhatsThisManager () 00100 { 00101 // go away... 00102 // tqApp -> installEventFilter (this); 00103 } 00104 00105 bool KWhatsThisManager::eventFilter (TQObject * /*o*/, TQEvent *e) 00106 { 00107 if (e -> type () == TQEvent::ChildInserted) { 00108 TQChildEvent *ce = (TQChildEvent *)e; 00109 // kdDebug () << "new qobject:" << ce -> child () << endl; 00110 if (ce -> child () -> isWidgetType ()) { 00111 TQWidget *w = (TQWidget *) (ce -> child ()); 00112 // kdDebug () << "new qwidget:" << w << endl; 00113 if (TQWhatsThis::textFor (w) . isEmpty ()) 00114 new KWhatsThisUndefined (w); 00115 } 00116 } 00117 return false; 00118 } 00119 00120 #include "kwhatsthismanager_p.moc" 00121