summaryrefslogtreecommitdiffstats
path: root/src/common/gui/purl_ext.cpp
blob: 82348b5dbd147fcc121b8dd734ef8ba0c45c3ae1 (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
/***************************************************************************
 *   Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/
#include "common/global/purl.h"

#include <tqfile.h>
#include <tqapplication.h>
#include <tdeio/netaccess.h>
#include <tdefileitem.h>
#include <ktempfile.h>
#include <tdeconfigbackend.h>

#include "common/global/pfile.h"

bool PURL::Url::copyTo(const Url &destination, Log::Generic &log) const
{
//#if defined(NO_KDE)
//  Synchronous sync;
//  if ( sync.op().copy(_url.filepath(), destination.filepath()) && sync.execute() ) {
//    if ( show==Log::Show ) ConsoleView::sorry(i18n("Could not copy file"), sync.error());
//    return false;
//  }
//#else
  // do not overwrite
  bool ok = TDEIO::NetAccess::file_copy(_url, destination._url, -1, false, false, tqApp->mainWidget());
  if ( !ok ) log.sorry(i18n("Could not copy file"), TDEIO::NetAccess::lastErrorString());
  return ok;
//#endif
}

bool PURL::Url::create(Log::Generic &log) const
{
//#if defined(NO_KDE)
//  TQByteArray a;
//  Synchronous sync;
//  if ( sync.op().put(a, _url.filepath()) && sync.execute() ) {
//    if ( show==Log::Show ) ConsoleView::sorry(i18n("Could not create file"), sync.error());
//    return false;
//  }
//#else
  // assume file do no exist if ioslave cannot tell...
  if ( TDEIO::NetAccess::exists(_url, false, tqApp->mainWidget()) ) return true;
  KTempFile tmp;
  tmp.setAutoDelete(true);
  // do not overwrite
  bool ok = TDEIO::NetAccess::file_copy(tmp.name(), _url, -1, false, false, tqApp->mainWidget());
  if ( !ok ) log.sorry(i18n("Could not create file"), TDEIO::NetAccess::lastErrorString());
//#endif
  return ok;
}

bool PURL::Url::write(const TQString &text, Log::Generic &log) const
{
  File file(*this, log);
  if ( !file.openForWrite() ) return false;
  file.stream() << text;
  return file.close();
}

bool PURL::Url::del(Log::Generic &log) const
{
//#if defined(NO_KDE)
//  Synchronous sync;
//  if ( sync.op().remove(_url.filepath()) && sync.execute() ) {
//    if ( show==Log::Show ) ConsoleView::sorry(i18n("Could not delete file"), sync.error());
//    return false;
//  }
//#else
  bool ok = TDEIO::NetAccess::del(_url, tqApp->mainWidget());
  if ( !ok ) log.sorry(i18n("Could not delete file."), TDEIO::NetAccess::lastErrorString());
  return ok;
//#endif
}

bool PURL::Url::isDosFile() const
{
  Log::Base log;
  File file(*this, log);
  if( !file.openForRead() ) return false;
  int oldc = 0;
  for (;;) {
    int c = file.qfile()->getch();
    if ( c==-1 )  break;
    if( c=='\n' && oldc=='\r' ) return true;
    oldc = c;
  }
  return false;
}

//-----------------------------------------------------------------------------
bool PURL::Directory::create(Log::Generic &log) const
{
//#if defined(NO_KDE)
//  Synchronous sync;
//  if ( sync.op().mkdir(_url.filepath()) && sync.execute() ) {
//    if ( show==Log::Show ) ConsoleView::sorry(i18n("Could not create directory"), sync.error());
//    return false;
//  }
//#else
  // assume dir do no exist if ioslave cannot tell...
  if ( TDEIO::NetAccess::exists(_url, false, tqApp->mainWidget()) ) return true;
  bool ok = TDEIO::NetAccess::mkdir(_url, tqApp->mainWidget());
  if ( !ok ) log.sorry(i18n("Could not create directory"), TDEIO::NetAccess::lastErrorString());
//#endif
  return ok;
}