summaryrefslogtreecommitdiffstats
path: root/quanta/components/debugger/pathmapperdialog.cpp
blob: 74e019563283aa634bc01cb947a81bc464e58067 (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
/***************************************************************************
                            pathmapperdialog.cpp
                            --------------------
    begin                : 2005-01-08
    copyright            : (C) 2004 Linus McCabe <linus@mccabe.nu>
 ***************************************************************************/

/****************************************************************************
 *                                                                          *
 *   This program is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by   *
 *   the Free Software Foundation; either version 2 of the License, or      *
 *   (at your option) any later version.                                    *
 *                                                                          *
 ***************************************************************************/


#include "pathmapperdialog.h"
#include <tqlistview.h>
#include <tqlineedit.h>
#include <qextfileinfo.h>
#include <tqcolor.h>
#include <kled.h>

PathMapperDialog::PathMapperDialog(const TQString& path, const PathMapperDialog::Direction direction)
    : PathMapperDialogS(0, "PathMapperDialog", false, 0)
{
  m_direction = direction;
  m_path = path;
  linePath->setText(path);

  if(m_direction == LocalToServer)
    ledTranslationExists->hide();
  
  connect(listHistory, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged()));
  connect(lineLocalPath, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotPathsChanged()));
  connect(lineServerPath, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotPathsChanged()));
}

PathMapperDialog::~PathMapperDialog()
{
}

void PathMapperDialog::addHistory(const TQString &serverdir, const TQString &localdir)
{
  new TQListViewItem(listHistory, localdir, serverdir);
}

void PathMapperDialog::slotSelectionChanged()
{
  lineLocalPath->setText(listHistory->currentItem()->text(0));
  lineServerPath->setText(listHistory->currentItem()->text(1));
}

void PathMapperDialog::slotPathsChanged()
{
  TQString translated, from, to;
  if(m_direction == ServerToLocal)
  {
    from = lineServerPath->text();
    to = lineLocalPath->text();
  }
  else
  {
    to = lineServerPath->text();
    from = lineLocalPath->text();
  }

  translated = m_path;
  
  // Check if this dir is matched by the maps
  if(m_path.startsWith(from, false))
  {
    translated.remove(0, from.length());
    translated = to + translated;
  }

  // Indicate wether local file exists
  if(m_direction == ServerToLocal)
  {
    if(QExtFileInfo::exists(translated, true, this))
      ledTranslationExists->setColor(Qt::green);
    else
      ledTranslationExists->setColor(Qt::red);
    ledTranslationExists->on();
  }

  lineTranslated->setText(translated);
}

TQString PathMapperDialog::serverPath()
{
  return lineServerPath->text();
}

TQString PathMapperDialog::localPath()
{
  return lineLocalPath->text();
}

#include "pathmapperdialog.moc"