• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
util.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "util.h"
21#include <tqstringlist.h>
22
23void urlToSmb(const KURL& url, TQString& work, TQString& server, TQString& printer)
24{
25 if (url.protocol() != "smb")
26 return;
27 TQString h = url.host();
28 TQStringList l = TQStringList::split('/', url.path(), false);
29 if (l.count() > 1)
30 {
31 work = h;
32 server = l[0];
33 printer = l[1];
34 }
35 else
36 {
37 work = TQString::null;
38 server = h;
39 printer = l[0];
40 }
41}
42
43KURL smbToUrl(const TQString& s)
44{
45 // allow to handle non-encoded chars in login/password
46 KURL url;
47 int p = s.find('@');
48 if (p == -1)
49 {
50 // assumes url starts with "smb://". Use encoding in
51 // case the printer name contains chars like '#'.
52 url = KURL("smb://" + KURL::encode_string(s.mid(6)));
53 }
54 else
55 {
56 // assumes URL starts with "smb://"
57 TQString username = s.mid(6, p-6);
58 url = KURL("smb://" + KURL::encode_string(s.mid(p+1)));
59 int q = username.find(':');
60 if (q == -1)
61 url.setUser(username);
62 else
63 {
64 url.setUser(username.left(q));
65 url.setPass(username.mid(q+1));
66 }
67 }
68 return url;
69}
70
71int findIndex(int ID)
72{
73 for (int i=0; i<KPrinter::NPageSize-1; i++)
74 if (page_sizes[i].ID == ID)
75 return i;
76 return 4;
77}
78
79TQString buildSmbURI( const TQString& work, const TQString& server, const TQString& printer, const TQString& user, const TQString& passwd )
80{
81 TQString uri = server + "/" + printer;
82 if ( !work.isEmpty() )
83 uri.prepend( work + "/" );
84 if ( !user.isEmpty() )
85 {
86 uri.prepend( "@" );
87 if ( !passwd.isEmpty() )
88 uri.prepend( ":" + passwd );
89 uri.prepend( user );
90 }
91 uri.prepend( "smb://" );
92 return uri;
93}
94
95bool splitSmbURI( const TQString& uri, TQString& work, TQString& server, TQString& printer, TQString& user, TQString& passwd )
96{
97 int p( 0 );
98 if ( !uri.startsWith( "smb://" ) )
99 return false;
100 p = 6;
101
102 int p1 = uri.find( '/', p );
103 if ( p1 != -1 )
104 {
105 int p2 = uri.find( '@', p );
106 if ( p2 != -1 && p2 < p1 )
107 {
108 // Got a user
109 int p3 = uri.find( ':', p );
110 if ( p3 != -1 && p3 < p2 )
111 {
112 // Got a password
113 user = uri.mid( p, p3-p );
114 passwd = uri.mid( p3+1, p2-p3-1 );
115 }
116 else
117 user = uri.mid( p, p2-p );
118 }
119 else
120 p2 = p-1;
121 TQStringList l = TQStringList::split( '/', uri.mid( p2+1 ), false );
122 switch ( l.count() )
123 {
124 case 3:
125 work = l[ 0 ];
126 server = l[ 1 ];
127 printer = l[ 2 ];
128 break;
129 case 2:
130 server = l[ 0 ];
131 printer = l[ 1 ];
132 break;
133 default:
134 return false;
135 }
136 return true;
137 }
138 return false;
139}

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.