summaryrefslogtreecommitdiffstats
path: root/konq-plugins/rsync/rsyncplugin.cpp
blob: 5f7498789985441e1b298d6bbbcd2b90b23144c8 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
   Copyright (C) 2000, 2001, 2002 Dawit Alemayehu <adawit@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>

#define HAVE_TERMIOS_H 1
#define HAVE_GRANTPT 1

#include <stdlib.h>
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#ifdef HAVE_STROPTS
#include <stropts.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#endif
#ifdef HAVE_UTIL_H
#include <util.h>
#endif

#include <tqfile.h>
#include <tqtimer.h>
#include <tqapplication.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqhbox.h>
#include <tqwhatsthis.h>
#include <tqiconview.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqlabel.h>
#include <layout.h>
#include <tqpushbutton.h>
#include <tqstring.h>
#include <tqregexp.h>
#include <tqstyle.h>
#include <tqtimer.h>

#include <kdebug.h>
#include <klocale.h>
#include <kinstance.h>

#include <twin.h>
#include <kurl.h>
#include <kaction.h>
#include <kpopupmenu.h>
#include <kmessagebox.h>
#include <kiconloader.h>
#include <kprogressbox.h>
#include <kpassdlg.h>
#include <klistview.h>
#include <kapplication.h>
#include <kconfigdialog.h>

#include <kdirlister.h>
#include <kstandarddirs.h>
#include <klistviewsearchline.h>
#include <kiconviewsearchline.h>
#include <konq_dirpart.h>
#include <konq_propsview.h>
#include <kstaticdeleter.h>
#include <kgenericfactory.h>
#include <kparts/browserextension.h>

#include <kio/global.h>
#include <kio/slavebase.h>

#include "rsyncplugin.h"

#define myDebug(x) kdDebug(7127) << __LINE__ << ": " x

#define CONFIGURATION_FILE_SEPARATOR ';'

typedef KGenericFactory<RsyncPlugin> RsyncPluginFactory;
K_EXPORT_COMPONENT_FACTORY(librsyncplugin,
                           RsyncPluginFactory("rsyncplugin"))

RsyncPlugin::RsyncPlugin (TQObject* parent, const char* name,
                                  const TQStringList&)
                :KParts::Plugin (parent, name),
                m_pSyncNow(0),
                m_pSyncSetup(0)
{
  m_part = ::tqqt_cast<KonqDirPart*>(parent);

  if ( !m_part || !m_part->scrollWidget() )
    return;

  m_pSyncNow = new KAction(i18n("Synchronize F&older"), "syncnow",
                               actionCollection(), "syncnow");
  m_pSyncSetup = new KAction (i18n("Setup Syn&chronization"), "setupsync",
                               actionCollection(), "setupsync");
  m_pSyncNow->setIcon("remotesync");
  m_pSyncSetup->setIcon("remotesyncconfig");
  m_pSyncNow->setEnabled (false);

  m_rSync = new KRsync(parent, name);

  connect (m_part, TQT_SIGNAL(aboutToOpenURL()), TQT_SLOT(slotOpenURL()));

  connect(m_pSyncNow, TQT_SIGNAL(activated()), this, TQT_SLOT(slotSync()));
  connect(m_pSyncSetup, TQT_SIGNAL(activated()), this, TQT_SLOT(slotSetup()));

  connect(m_rSync, TQT_SIGNAL(setupDone()), this, TQT_SLOT(slotSetupDone()));
  connect(m_rSync, TQT_SIGNAL(transferDone()), this, TQT_SLOT(slotTransferDone()));

  m_rSync->loadSettings();
}

RsyncPlugin::~RsyncPlugin()
{
  delete m_pSyncNow;
  delete m_pSyncSetup;
}

// --------------------------------------------------------------------------------------------
//
// Here begins the standard load/save/search/Konqy stuff
//
// --------------------------------------------------------------------------------------------

void RsyncPlugin::slotOpenURL ()
{
  KURL url = m_part->url();
  m_rSync->setCurrentDirectoryURL(url);

  if (m_pURL != url)
  {
	// See if this URL is "/", "/dev", or "/proc", and disable sync if so
	// Also disable sync for non-"file://" URLs
	if ((url.directory(true, true) + TQString("/") + url.fileName(true)) == "//") {
		m_pSyncSetup->setEnabled(false);
		m_pSyncNow->setEnabled(false);
	}
	else if (((url.directory(true, true) + TQString("/") + url.fileName(true)).left(5) == "//dev") || ((url.directory(true, true) + TQString("/") + url.fileName(true)).left(4) == "/dev")) {
		m_pSyncSetup->setEnabled(false);
		m_pSyncNow->setEnabled(false);
	}
	else if (((url.directory(true, true) + TQString("/") + url.fileName(true)).left(6) == "//proc") || ((url.directory(true, true) + TQString("/") + url.fileName(true)).left(5) == "/proc")) {
		m_pSyncSetup->setEnabled(false);
		m_pSyncNow->setEnabled(false);
	}
	else if (url.protocol() != TQString("file")) {
		m_pSyncSetup->setEnabled(false);
		m_pSyncNow->setEnabled(false);
	}
	else {
		m_pSyncSetup->setEnabled(true);

		// See if this URL is in the list of rsync-able directories
		if (m_rSync->findLocalFolderByName(url.directory(true, true) + TQString("/") + url.fileName(true)) != NULL) {
			m_pSyncNow->setEnabled (true);
		}
		else {
			m_pSyncNow->setEnabled (false);
		}
	}
  }
  m_pURL = url;
}

void RsyncPlugin::slotSetup()
{
	KURL url = m_part->url();
	m_rSync->setCurrentDirectoryURL(url);

	m_pSyncSetup->setEnabled (false);
	m_rSync->slotSetup();
}

void RsyncPlugin::slotSetupDone()
{
	m_pSyncSetup->setEnabled (true);
}

void RsyncPlugin::slotTransferDone()
{
	m_pSyncNow->setEnabled (true);
}

void RsyncPlugin::slotSync()
{
	if (!m_part)
		return;

	KURL url = m_part->url();
	m_rSync->setCurrentDirectoryURL(url);

	m_rSync->slotSync();
}

#include "rsyncplugin.moc"