summaryrefslogtreecommitdiffstats
path: root/kftpgrabber/src/kftpfileexistsactions.cpp
blob: 5ebf5880380885504fefd8ba34cecc014bf0e989 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * This file is part of the KFTPGrabber project
 *
 * Copyright (C) 2003-2004 by the KFTPGrabber developers
 * Copyright (C) 2003-2004 Jernej Kos <kostko@jweb-network.net>
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but
 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
 * NON-INFRINGEMENT.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations
 * including the two.
 * You must obey the GNU General Public License in all respects
 * for all of the code used other than OpenSSL.  If you modify
 * file(s) with this exception, you may extend this exception to your
 * version of the file(s), but you are not obligated to do so.  If you
 * do not wish to do so, delete this exception statement from your
 * version.  If you delete this exception statement from all source
 * files in the program, then also delete it here.
 */

#include "kftpfileexistsactions.h"

#include <ntqlayout.h>
#include <ntqgroupbox.h>
#include <ntqlabel.h>

#include <kdialog.h>
#include <kcombobox.h>
#include <tdelocale.h>

namespace KFTPQueue {

TQString &operator<<(TQString &s, const FileExistsActions &a)
{
  s.truncate(0);
  
  ActionMap::ConstIterator end( a.m_actions.end() );
  for (ActionMap::ConstIterator i( a.m_actions.begin() ); i != end; ++i) {
    s.append(TQString("%1;").arg(i.data()));
  }
  
  return s;
}

TQString &operator>>(TQString &s, FileExistsActions &a)
{
  for (unsigned int i = 0; i < 9; i++) {
    a.m_actions[i+1] = static_cast<FEAction>(s.section(';', i, i).toInt());
  }
  
  return s;
}

TQWidget *FileExistsActions::getConfigWidget(TQWidget *parent)
{
  TQGroupBox *gb = new TQGroupBox(0, TQt::Vertical, i18n("On File Exists Actions (%1)").arg(m_type), parent);
  gb->layout()->setSpacing(KDialog::spacingHint());
  gb->layout()->setMargin(KDialog::marginHint());
  
  TQGridLayout *gl = new TQGridLayout(gb->layout(), 5, 4, 5);
  
  TQLabel *l = new TQLabel(i18n("Size/Timestamp"), gb);
  gl->addWidget(l, 1, 0);
  
  l = new TQLabel(i18n("Same"), gb);
  gl->addWidget(l, 1, 1);
  
  l = new TQLabel(i18n("Older"), gb);
  gl->addWidget(l, 1, 2);
  
  l = new TQLabel(i18n("Newer"), gb);
  gl->addWidget(l, 1, 3);
  
  l = new TQLabel(i18n("Same"), gb);
  gl->addWidget(l, 2, 0);
  
  l = new TQLabel(i18n("Smaller"), gb);
  gl->addWidget(l, 3, 0);
  
  l = new TQLabel(i18n("Bigger"), gb);
  gl->addWidget(l, 4, 0);
  
  for (int row = 0; row < 3; row++) {
    for (int col = 0; col < 3; col++) {
      KComboBox *cb = new KComboBox(gb);
      m_combos[row][col] = cb;
      
      cb->insertItem(i18n("Skip"));
      cb->insertItem(i18n("Overwrite"));
      cb->insertItem(i18n("Resume"));
      cb->insertItem(i18n("Rename"));
      cb->insertItem(i18n("Ask"));
      cb->setCurrentItem(m_actions[row * 3 + col + 1]);
      
      gl->addWidget(cb, row+2, col+1);
    }
  }
  
  return gb;
}

void FileExistsActions::updateWidget()
{
  for (int row = 0; row < 3; row++) {
    for (int col = 0; col < 3; col++) {
      m_combos[row][col]->setCurrentItem(m_actions[row * 3 + col + 1]);
    }
  }
}

void FileExistsActions::updateConfig()
{
  for (int row = 0; row < 3; row++) {
    for (int col = 0; col < 3; col++) {
      m_actions[row * 3 + col + 1] = static_cast<FEAction>(m_combos[row][col]->currentItem());
    }
  }
}

FEAction FileExistsActions::getActionForSituation(filesize_t src_fileSize, time_t src_fileTimestamp,
                                                  filesize_t dst_fileSize, time_t dst_fileTimestamp)
{
  // There are 9 different scenarios
  int situation = -1;
  
  if (dst_fileTimestamp == src_fileTimestamp) {
    // SAME TIMESTAMP
    situation = 1;
  } else if (dst_fileTimestamp < src_fileTimestamp) {
    // OLDER
    situation = 2;
  } else {
    // NEWER
    situation = 3;
  }
  
  if (dst_fileSize < src_fileSize) {
    // SMALLER FILE
    situation += 3;
  } else if (dst_fileSize > src_fileSize) {
    // BIGGER FILE
    situation += 6;
  }
  
  // Situation calculated, now get the action
  return m_actions[situation];
}

}