summaryrefslogtreecommitdiffstats
path: root/quanta/dialogs/dirtydlg.cpp
blob: 3664f21f9b41e33cf54d1d5c0b674e9d72e4c9dc (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
/***************************************************************************
                          dirtydlg.cpp  -  description
                             -------------------
    begin                : Fri Sep 13 2002
    copyright            : (C) 2002, 2003 by Andras Mantia <amantia@kde.org>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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; version 2 of the License.               *
 *                                                                         *
 ***************************************************************************/

//qt includes
#include <tqevent.h>
#include <tqlabel.h>
#include <tqradiobutton.h>
#include <tqpushbutton.h>

//kde includes
#include <kdialogbase.h>
#include <klocale.h>
#include <kprocess.h>
#include <kio/job.h>
#include <kio/jobclasses.h>
#include <kio/netaccess.h>
#include <kfileitem.h>

//app includes
#include "dirtydialog.h"
#include "dirtydlg.h"
#include "resource.h"
#include "qextfileinfo.h"

DirtyDlg::DirtyDlg(const TQString& srcName, const TQString& destName, bool createBackup, TQWidget *parent, const char *name ) : KDialogBase(parent, name, true, i18n("File Changed"), KDialogBase::Ok)
{
 m_src.setPath(srcName);
 m_dest.setPath(destName);
 m_busy = false;
 m_createBackup = createBackup;
 m_mainWidget = new DirtyDialog(this);
 m_mainWidget->textLabel->setText(i18n("<qt>The file <b>%1</b> was changed outside of the Quanta editor.</qt>").arg(srcName));
 setMainWidget(m_mainWidget);
}

DirtyDlg::~DirtyDlg(){
}
/** No descriptions */
void DirtyDlg::slotOk()
{
 if (m_mainWidget->buttonCompare->isChecked())
 {
   m_busy = true;
   TDEProcess *proc = new TDEProcess();
   *proc << "kompare" << m_src.path() << m_dest.path();
   proc->start();
   connect(proc, TQT_SIGNAL(processExited(TDEProcess*)),TQT_SLOT(slotCompareDone(TDEProcess*)));
   enableButton(KDialogBase::Ok, false);
   enableButton(KDialogBase::Cancel, false);
 } else
 if (m_mainWidget->buttonLoad->isChecked())
 {
    accept();
 } else
 {
    reject();
 }
}

/** No descriptions */
void DirtyDlg::slotCompareDone(TDEProcess* proc)
{
 delete proc;

 if (m_createBackup)
 {
   KURL backupURL = m_src;
   backupURL.setPath(backupURL.path()+".backup");
   QExtFileInfo::copy(m_src, backupURL, -1, true, false, this);
 }

 KIO::UDSEntry entry;
 KIO::NetAccess::stat(m_src, entry, this);
 KFileItem item(entry, m_src, false, true);
 m_permissions = item.permissions();
 //TODO: Replace with KIO::NetAccess::file_move, when KDE 3.1 support
 //is dropped
 KIO::FileCopyJob *job = KIO::file_move(m_dest, m_src, m_permissions, true, false,false );
 connect( job, TQT_SIGNAL(result( KIO::Job *)),
                 TQT_SLOT  (slotResult( KIO::Job *)));
}


/** No descriptions */
void DirtyDlg::slotResult(KIO::Job *)
{
 m_busy = false;
 accept();
}

/** No descriptions */
void DirtyDlg::closeEvent(TQCloseEvent* ev)
{
  if (m_busy)
    ev->ignore();
  else
    ev->accept();
}

#include "dirtydlg.moc"