28#include <tqobjectlist.h> 
   30#include <tqpushbutton.h> 
   31#include <tqwhatsthis.h> 
   32#include <tqgroupbox.h> 
   33#include <tqwidgetfactory.h> 
   37#include <tdeaboutdata.h> 
   41#include <tdelistview.h> 
   44#include <tdestandarddirs.h> 
   45#include <kactivelabel.h> 
   47#include <tdefiledialog.h> 
   48#include <tdemessagebox.h> 
   49#include <tdeprocess.h> 
   50#include <tdeio/netaccess.h> 
   52#include "kcmdesignerfields.h" 
   56class PageItem : 
public TQCheckListItem
 
   59    PageItem( TQListView *parent, 
const TQString &path )
 
   60      : TQCheckListItem( parent, 
"", TQCheckListItem::CheckBox ),
 
   61        mPath( path ), mIsActive( false )
 
   63      mName = path.mid( path.findRev( 
'/' ) + 1 );
 
   65      TQWidget *wdg = TQWidgetFactory::create( mPath, 0, 0 );
 
   67        setText( 0, wdg->caption() );
 
   69        TQPixmap pm = TQPixmap::grabWidget( wdg );
 
   70        TQImage img = pm.convertToImage().smoothScale( 300, 300, TQImage::ScaleMin );
 
   73        TQObjectList *list = wdg->queryList( 
"TQWidget" );
 
   74        TQObjectListIt it( *list );
 
   76        TQMap<TQString, TQString> allowedTypes;
 
   77        allowedTypes.insert( 
"TQLineEdit", i18n( 
"Text" ) );
 
   78        allowedTypes.insert( 
"TQTextEdit", i18n( 
"Text" ) );
 
   79        allowedTypes.insert( 
"TQSpinBox", i18n( 
"Numeric Value" ) );
 
   80        allowedTypes.insert( 
"TQCheckBox", i18n( 
"Boolean" ) );
 
   81        allowedTypes.insert( 
"TQComboBox", i18n( 
"Selection" ) );
 
   82        allowedTypes.insert( 
"TQDateTimeEdit", i18n( 
"Date & Time" ) );
 
   83        allowedTypes.insert( 
"KLineEdit", i18n( 
"Text" ) );
 
   84        allowedTypes.insert( 
"KDateTimeWidget", i18n( 
"Date & Time" ) );
 
   85        allowedTypes.insert( 
"KDatePicker", i18n( 
"Date" ) );
 
   87        while ( it.current() ) {
 
   88          if ( allowedTypes.find( it.current()->className() ) != allowedTypes.end() ) {
 
   89            TQString name = it.current()->name();
 
   90            if ( name.startsWith( 
"X_" ) ) {
 
   91              new TQListViewItem( 
this, name,
 
   92                                 allowedTypes[ it.current()->className() ],
 
   93                                 it.current()->className(),
 
   94                                 TQWhatsThis::textFor( 
static_cast<TQWidget*
>( it.current() ) ) );
 
  105    TQString name()
 const { 
return mName; }
 
  106    TQString path()
 const { 
return mPath; }
 
  113    void setIsActive( 
bool isActive ) { mIsActive = isActive; }
 
  114    bool isActive()
 const { 
return mIsActive; }
 
  117    void paintBranches( TQPainter *p, 
const TQColorGroup & cg, 
int w, 
int y, 
int h )
 
  119      TQListViewItem::paintBranches( p, cg, w, y, h );
 
  129KCMDesignerFields::KCMDesignerFields( TQWidget *parent, 
const char *name )
 
  130  : TDECModule( parent, name )
 
  132  TQTimer::singleShot( 0, 
this, TQ_SLOT( delayedInit() ) );
 
  134  TDEAboutData *about = 
new TDEAboutData( I18N_NOOP( 
"KCMDesignerfields" ),
 
  135                                      I18N_NOOP( 
"TQt Designer Fields Dialog" ),
 
  136                                      0, 0, TDEAboutData::License_LGPL,
 
  137                                      I18N_NOOP( 
"(c), 2004 Tobias Koenig" ) );
 
  139  about->addAuthor( 
"Tobias Koenig", 0, 
"tokoe@kde.org" );
 
  140  about->addAuthor( 
"Cornelius Schumacher", 0, 
"schumacher@kde.org" );
 
  141  setAboutData( about );
 
  144void KCMDesignerFields::delayedInit()
 
  146  kdDebug() << 
"KCMDesignerFields::delayedInit()" << endl;
 
  150  connect( mPageView, TQ_SIGNAL( selectionChanged( TQListViewItem* ) ),
 
  151           this, TQ_SLOT( updatePreview( TQListViewItem* ) ) );
 
  152  connect( mPageView, TQ_SIGNAL( clicked( TQListViewItem* ) ),
 
  153           this, TQ_SLOT( itemClicked( TQListViewItem* ) ) );
 
  155  connect( mDeleteButton, TQ_SIGNAL( clicked() ),
 
  156           this, TQ_SLOT( deleteFile() ) );
 
  157  connect( mImportButton, TQ_SIGNAL( clicked() ),
 
  158           this, TQ_SLOT( importFile() ) );
 
  159  connect( mDesignerButton, TQ_SIGNAL( clicked() ),
 
  160           this, TQ_SLOT( startDesigner() ) );
 
  165  KDirWatch *dw = 
new KDirWatch( 
this );
 
  166  TDEStandardDirs::makeDir(localUiDir());
 
  167  dw->addDir( localUiDir(), 
true );
 
  168  connect( dw, TQ_SIGNAL( created(
const TQString&) ), TQ_SLOT( rebuildList() ) );
 
  169  connect( dw, TQ_SIGNAL( deleted(
const TQString&) ), TQ_SLOT( rebuildList() ) );
 
  170  connect( dw, TQ_SIGNAL( dirty(
const TQString&) ),   TQ_SLOT( rebuildList() ) );
 
  173void KCMDesignerFields::deleteFile()
 
  175  TQListViewItem *item = mPageView->selectedItem();
 
  177    PageItem *pageItem = 
static_cast<PageItem*
>( item->parent() ? item->parent() : item );
 
  178    if (KMessageBox::warningContinueCancel(
this,
 
  179    i18n( 
"<qt>Do you really want to delete '<b>%1</b>'?</qt>").arg( pageItem->text(0) ), 
"", KStdGuiItem::del() )
 
  180         == KMessageBox::Continue)
 
  181      TDEIO::NetAccess::del( pageItem->path(), 0 );
 
  186void KCMDesignerFields::importFile()
 
  188  KURL src = KFileDialog::getOpenFileName( TQDir::homeDirPath(), i18n(
"*.ui|Designer Files"),
 
  189                                              this, i18n(
"Import Page") );
 
  190  KURL dest = localUiDir();
 
  191  dest.setFileName(src.fileName());
 
  192  TDEIO::NetAccess::file_copy( src, dest, -1, 
true, 
false, 
this );
 
  197void KCMDesignerFields::loadUiFiles()
 
  199  TQStringList list = TDEGlobal::dirs()->findAllResources( 
"data", uiPath() + 
"/*.ui", 
true, 
true );
 
  200  for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) {
 
  201    new PageItem( mPageView, *it );
 
  205void KCMDesignerFields::rebuildList()
 
  207  TQStringList ai = saveActivePages();
 
  214void KCMDesignerFields::loadActivePages(
const TQStringList& ai)
 
  216  TQListViewItemIterator it( mPageView );
 
  217  while ( it.current() ) {
 
  218    if ( it.current()->parent() == 0 ) {
 
  219      PageItem *item = 
static_cast<PageItem*
>( it.current() );
 
  220      if ( ai.find( item->name() ) != ai.end() ) {
 
  222        item->setIsActive( 
true );
 
  230void KCMDesignerFields::load()
 
  232  loadActivePages( readActivePages() );
 
  235TQStringList KCMDesignerFields::saveActivePages()
 
  237  TQListViewItemIterator it( mPageView, TQListViewItemIterator::Checked |
 
  238                            TQListViewItemIterator::Selectable );
 
  240  TQStringList activePages;
 
  241  while ( it.current() ) {
 
  242    if ( it.current()->parent() == 0 ) {
 
  243      PageItem *item = 
static_cast<PageItem*
>( it.current() );
 
  244      activePages.append( item->name() );
 
  253void KCMDesignerFields::save()
 
  255  writeActivePages( saveActivePages() );
 
  258void KCMDesignerFields::defaults()
 
  262void KCMDesignerFields::initGUI()
 
  264  TQVBoxLayout *layout = 
new TQVBoxLayout( 
this, KDialog::marginHint(),
 
  265                                         KDialog::spacingHint() );
 
  267  bool noDesigner = TDEStandardDirs::findExe(
"designer").isEmpty();
 
  272      i18n(
"<qt><b>Warning:</b> TQt Designer could not be found. It is probably not " 
  273         "installed. You will only be able to import existing designer files.</qt>");
 
  274    TQLabel *lbl = 
new TQLabel( txt, 
this );
 
  275    layout->addWidget( lbl );
 
  278  TQHBoxLayout *hbox = 
new TQHBoxLayout( layout, KDialog::spacingHint() );
 
  280  mPageView = 
new TDEListView( 
this );
 
  281  mPageView->addColumn( i18n( 
"Available Pages" ) );
 
  282  mPageView->setRootIsDecorated( 
true );
 
  283  mPageView->setAllColumnsShowFocus( 
true );
 
  284  mPageView->setFullWidth( 
true );
 
  285  hbox->addWidget( mPageView );
 
  287  TQGroupBox *box = 
new TQGroupBox(1, TQt::Horizontal, i18n(
"Preview of Selected Page"), 
this );
 
  289  mPagePreview = 
new TQLabel( box );
 
  290  mPagePreview->setMinimumWidth( 300 );
 
  292  mPageDetails = 
new TQLabel( box );
 
  294  hbox->addWidget( box );
 
  298  hbox = 
new TQHBoxLayout( layout, KDialog::spacingHint() );
 
  300  TQString cwHowto = i18n(
"<qt><p>This section allows you to add your own GUI" 
  301                         "  Elements ('<i>Widgets</i>') to store your own values" 
  302                         " into %1. Proceed as described below:</p>" 
  304                         "<li>Click on '<i>Edit with TQt Designer</i>'" 
  305                         "<li>In the dialog, select '<i>Widget</i>', then click <i>OK</i>" 
  306                         "<li>Add your widgets to the form" 
  307                         "<li>Save the file in the directory proposed by TQt Designer" 
  308                         "<li>Close TQt Designer" 
  310                         "<p>In case you already have a designer file (*.ui) located" 
  311                         " somewhere on your hard disk, simply choose '<i>Import Page</i>'</p>" 
  312                         "<p><b>Important:</b> The name of each input widget you place within" 
  313                         " the form must start with '<i>X_</i>'; so if you want the widget to" 
  314                         " correspond to your custom entry '<i>X-Foo</i>', set the widget's" 
  315                         " <i>name</i> property to '<i>X_Foo</i>'.</p>" 
  316                         "<p><b>Important:</b> The widget will edit custom fields with an" 
  317                         " application name of %2.  To change the application name" 
  318                         " to be edited, set the widget name in TQt Designer.</p></qt>" )
 
  319                         .arg( applicationName(), applicationName() );
 
  321  KActiveLabel *activeLabel = 
new KActiveLabel(
 
  322      i18n( 
"<a href=\"whatsthis:%1\">How does this work?</a>" ).arg(cwHowto), 
this );
 
  323  hbox->addWidget( activeLabel );
 
  326  activeLabel->setSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Maximum );
 
  328  hbox->addStretch( 1 );
 
  330  mDeleteButton = 
new TQPushButton( i18n( 
"Delete Page" ), 
this);
 
  331  mDeleteButton->setEnabled( 
false );
 
  332  hbox->addWidget( mDeleteButton );
 
  333  mImportButton = 
new TQPushButton( i18n( 
"Import Page..." ), 
this);
 
  334  hbox->addWidget( mImportButton );
 
  335  mDesignerButton = 
new TQPushButton( i18n( 
"Edit with TQt Designer..." ), 
this );
 
  336  hbox->addWidget( mDesignerButton );
 
  339    mDesignerButton->setEnabled( 
false );
 
  346  mDeleteButton->show();
 
  347  mImportButton->show();
 
  348  mDesignerButton->show();
 
  351void KCMDesignerFields::updatePreview( TQListViewItem *item )
 
  353  bool widgetItemSelected = 
false;
 
  356    if ( item->parent() ) {
 
  357      TQString details = TQString( 
"<qt><table>" 
  358                                 "<tr><td align=\"right\"><b>%1</b></td><td>%2</td></tr>" 
  359                                 "<tr><td align=\"right\"><b>%3</b></td><td>%4</td></tr>" 
  360                                 "<tr><td align=\"right\"><b>%5</b></td><td>%6</td></tr>" 
  361                                 "<tr><td align=\"right\"><b>%7</b></td><td>%8</td></tr>" 
  363                                .arg( i18n( 
"Key:" ) )
 
  364                                .arg( item->text( 0 ).replace(
"X_",
"X-") )
 
  365                                .arg( i18n( 
"Type:" ) )
 
  366                                .arg( item->text( 1 ) )
 
  367                                .arg( i18n( 
"Classname:" ) )
 
  368                                .arg( item->text( 2 ) )
 
  369                                .arg( i18n( 
"Description:" ) )
 
  370                                .arg( item->text( 3 ) );
 
  372      mPageDetails->setText( details );
 
  374      PageItem *pageItem = 
static_cast<PageItem*
>( item->parent() );
 
  375      mPagePreview->setPixmap( pageItem->preview() );
 
  377      mPageDetails->setText( TQString() );
 
  379      PageItem *pageItem = 
static_cast<PageItem*
>( item );
 
  380      mPagePreview->setPixmap( pageItem->preview() );
 
  382      widgetItemSelected = 
true;
 
  385    mPagePreview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
 
  387    mPagePreview->setPixmap( TQPixmap() );
 
  388    mPagePreview->setFrameStyle( 0 );
 
  389    mPageDetails->setText( TQString() );
 
  392  mDeleteButton->setEnabled( widgetItemSelected );
 
  395void KCMDesignerFields::itemClicked( TQListViewItem *item )
 
  397  if ( !item || item->parent() != 0 )
 
  400  PageItem *pageItem = 
static_cast<PageItem*
>( item );
 
  402  if ( pageItem->isOn() != pageItem->isActive() ) {
 
  403    emit changed( 
true );
 
  404    pageItem->setIsActive( pageItem->isOn() );
 
  408void KCMDesignerFields::startDesigner()
 
  410  TQString cmdLine = 
"designer";
 
  413  TQString cepPath = localUiDir();
 
  414  if( !TDEGlobal::dirs()->exists(cepPath) ) {
 
  415    TDEIO::NetAccess::mkdir( cepPath, 
this );
 
  419  chdir(cepPath.local8Bit());
 
  421  TQListViewItem *item = mPageView->selectedItem();
 
  423    PageItem *pageItem = 
static_cast<PageItem*
>( item->parent() ? item->parent() : item );
 
  424    cmdLine += 
" " + TDEProcess::quote( pageItem->path() );
 
  427  KRun::runCommand( cmdLine );
 
  430#include "kcmdesignerfields.moc" 
TDEPIM classes for drag and drop of mails.