summaryrefslogtreecommitdiffstats
path: root/ksirc/puke/pkfiledialog.cpp
blob: f78ae895f49033558a8f9ba9c3597c468f811de7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <stdio.h>


#include <kdebug.h>

#include "pkfiledialog.h"
#include "pkfiledialog-cmd.h"

PObject *
PKFileDialog::createWidget(CreateArgs &ca)
{
  PKFileDialog *pw = new PKFileDialog(ca.parent);
  KFileDialog *kfbd;
  if(ca.fetchedObj != 0 && ca.fetchedObj->inherits("KFileDialog") == TRUE){
    kfbd = (KFileDialog *) ca.fetchedObj;
    pw->setDeleteAble(FALSE);
  }
  else // Never takes a parent in Puke
    kfbd = new KFileDialog("/", TQString::null, 0L, "PukeKFileDialog", TRUE);
  pw->setWidget(kfbd);
  pw->setWidgetId(ca.pwI);
  return pw;
}


PKFileDialog::PKFileDialog(PObject *parent)
  : PWidget(parent)
{
  kfbd = 0;
  setWidget(kfbd);
}

PKFileDialog::~PKFileDialog()
{
  //  kdDebug(5008) << "PLineEdit: in destructor" << endl;
  /*
  delete widget();     // Delete the frame
  kfbd=0;          // Set it to 0
  setWidget(kfbd); // Now set all widget() calls to 0.
  */
}

void PKFileDialog::messageHandler(int fd, PukeMessage *pm)
{
  TQString selFile;
  PukeMessage pmRet;
  if(widget() == 0){
    kdDebug(5008) << "PKFileDialog: No Widget set" << endl;
    return;
  }
  switch(pm->iCommand){
  case PUKE_KBFD_SET_PATH:
    ((KFileDialog*)widget())->setURL(KURL(pm->cArg));
    
    pmRet.iCommand = - pm->iCommand;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.iTextSize = widget()->baseURL().path().length();
#warning check if the cast is okay
    pmRet.cArg = (char*) widget()->baseURL().path().ascii();
    emit outputMessage(fd, &pmRet);
    break;
  case PUKE_KBFD_SET_FILTER:
    widget()->setFilter(pm->cArg);
    
    pmRet.iCommand = - pm->iCommand;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.iTextSize = 0;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);
    break;
  case PUKE_KBFD_SET_SELECTION:
    widget()->setSelection(pm->cArg);
    
    pmRet.iCommand = - pm->iCommand;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    selFile = widget()->selectedURL().path();
    pmRet.iTextSize = selFile.length();
#warning check if the cast is okay
    pmRet.cArg = (char*) selFile.ascii();
    emit outputMessage(fd, &pmRet);
    break;
  case PUKE_WIDGET_SHOW:
    widget()->exec();
    pmRet.iCommand = PUKE_KBFD_FILE_SELECTED_ACK;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.cArg = new char[selFile.length()];
    selFile = widget()->selectedURL().path();
    // #### HPB: using strlen() 'cause we want the length of the .ascii()
    //           string. We should probably replace in the future.
    memcpy(pmRet.cArg, selFile.ascii(), strlen(selFile.ascii()));
    pmRet.iTextSize = selFile.length();
    emit outputMessage(widgetIden().fd, &pmRet);
    delete pmRet.cArg;
    break;

  default:
    PWidget::messageHandler(fd, pm);
  }
}

void PKFileDialog::setWidget(TQObject *_kbfd)
{
  if(_kbfd != 0 && _kbfd->inherits("KFileBaseDialog") == FALSE)
  {
    errorInvalidSet(_kbfd);
    return;
  }

  kfbd = (KFileDialog *) _kbfd;
  PWidget::setWidget(kfbd);
}


KFileDialog *PKFileDialog::widget()
{
  return kfbd;
}

#include "pkfiledialog.moc"