2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: ToolTalk.c /main/6 1999/09/16 13:41:16 mgreess $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: Contains routines to handle tooltalk messages.
33 * FUNCTIONS: FileCallback
34 * FinalizeToolTalkSession
35 * InitializeToolTalkProcid
36 * InitializeToolTalkSession
41 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
42 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
43 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
44 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
46 ****************************************************************************
47 ************************************<+>*************************************/
50 #include <Xm/DrawingA.h>
51 #include <Xm/DrawingAP.h>
52 #include <Xm/MessageB.h>
53 #include <Xm/RowColumn.h>
54 #include <Xm/MwmUtil.h>
58 #include <Dt/IconFile.h>
60 #include <Dt/HelpDialog.h>
63 #include <X11/extensions/shape.h>
66 #include <X11/Shell.h>
67 #include <X11/Xatom.h>
68 #include <Xm/Protocols.h>
70 #include <Dt/Session.h>
72 #include <Dt/Connect.h>
74 #include <Dt/Indicator.h>
76 #include <Dt/UserMsg.h>
79 #include <Dt/DtNlUtils.h>
80 #include <Dt/CommandM.h>
81 #include <Dt/EnvControlP.h>
86 #include "SharedProcs.h"
91 /* ToolTalk messages */
92 #define FM_TT_MSG_QUIT "Quit"
93 #define FM_TT_MSG_PAUSE "Pause"
94 #define FM_TT_MSG_RESUME "Resume"
95 #define FM_TT_MSG_GET_STAT "Get_Status"
96 #define FM_TT_MSG_DO_CMD "Do_Command"
101 static char* RESTRICTED_HEADER = "-restricted";
103 static Tt_pattern * FileManagerToolTalkPattern = NULL;
104 static Boolean sendStopped = False;
105 XtInputId ProcessToolTalkInputId = 0;
117 View *view = clientdata;
118 char local_host[MAXHOSTNAMELEN];
119 extern char home_host_name[];
123 DialogData *dialog_data;
131 to_file = tt_message_arg_val(msg, 1);
132 strcpy(local_host, home_host_name);
133 dialog_data = (DialogData *)view->dialog_data;
134 ShowNewDirectory( (FileMgrData *)dialog_data->data,
135 local_host, to_file);
137 /* Quit the old file, join the new */
138 ttdt_file_quit( view->pats, 0 );
139 view->pats = ttdt_file_join( to_file, TT_SESSION,
140 0, FileCallback, view );
141 if (tt_is_err( tt_ptr_error( view->pats ))) {
145 tttk_message_destroy( msg );
154 FinalizeToolTalkSession(void)
159 for (i = 0; i < view_count; i++)
161 if (view_set[i]->msg != 0) {
162 if (view_set[i]->pats != 0) {
163 ttdt_file_quit( view_set[i]->pats, 0 );
164 view_set[i]->pats = 0;
166 tt_message_reply( view_set[i]->msg );
167 tttk_message_destroy( view_set[i]->msg );
168 view_set[i]->msg = 0;
172 if( FileManagerToolTalkPattern &&
173 tt_ptr_error( FileManagerToolTalkPattern ) == TT_OK )
175 ttRc = ttdt_session_quit( NULL,
176 FileManagerToolTalkPattern,
178 if( ProcessToolTalkInputId )
179 XtRemoveInput( ProcessToolTalkInputId );
181 ttRc = ttdt_close( NULL, NULL, sendStopped );
185 ToolTalkError( char * procName, Tt_status errId )
187 if( tt_is_err( errId ) )
192 XtRemoveInput( ProcessToolTalkInputId );
201 SessionCallback( Tt_message msg, void * client_data, Tt_message contract )
203 View *view = client_data;
204 char *opString = tt_message_op( msg );
205 Tttk_op op = tttk_string_op( opString );
214 tt_message_reply( msg );
215 FinalizeToolTalkSession( );
219 * Instead of quitting the whole process, we are to just
220 * quit the view associated with contract.
223 tttk_message_fail( msg, TT_DESKTOP_EINVAL, 0, 1 );
226 CloseView( (DialogData *)view->dialog_data );
227 tt_message_reply( msg );
228 tttk_message_destroy( msg );
235 MediaCallback( Tt_message msg,
239 unsigned char * contents,
245 Boolean restricted = False;
253 tttk_message_fail( msg, TT_DESKTOP_ENODATA, 0, 1 );
256 /* Buffers and files are the same to dtfile */
257 /* ToolTalk buffers are always null-terminated */
259 file = (char *)contents;
262 /* Old libtt SEGVs if you ask for a context that is not there */
263 if (tt_message_contexts_count( msg ) > 0) {
264 ceiling = tt_message_context_val( msg, "restricted" );
265 if (! tt_is_err( tt_ptr_error( ceiling ))) {
266 if ((ceiling == 0) || (strcmp( ceiling, "." ) != 0)) {
267 tttk_message_fail( msg,
268 TT_DESKTOP_ENOTSUP, 0, 1 );
280 * Create a display of the given directory tree
282 ViewDirectoryProc( file, restricted, msg );
287 tt_free( (caddr_t)contents );
292 InitializeToolTalkProcid( int *ttFd, Widget topLevel, Boolean sendStarted )
297 #ifdef DT_PERFORMANCE
298 printf(" InitializeToolTalkProcid\n");
299 gettimeofday(&update_time_s, NULL);
301 sendStopped = sendStarted;
302 procId = ttdt_open( ttFd,
308 #ifdef DT_PERFORMANCE
309 gettimeofday(&update_time_f, NULL);
310 if (update_time_s.tv_usec > update_time_f.tv_usec) {
311 update_time_f.tv_usec += 1000000;
312 update_time_f.tv_sec--;
314 printf(" done InitializeToolTalkProcid, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
317 if( (ttstat = tt_ptr_error( procId )) == TT_OK )
319 ProcessToolTalkInputId =
320 XtAppAddInput( XtWidgetToApplicationContext( toplevel ),
321 *ttFd, (XtPointer)XtInputReadMask,
322 tttk_Xt_input_handler, procId );
327 ttdt_close( NULL, NULL, sendStopped );
334 InitializeToolTalkSession( Widget topLevel, int ttFd )
338 ttstat = ttmedia_ptype_declare( "DT_File_Manager",
344 ttstat = ttmedia_ptype_declare( "DT_File_Manager",
349 tt_ptype_opnum_callback_add( "DT_File_Manager", 0, HandleTtRequest );
353 * If we were started by a message, the following call to
354 * tttk_Xt_input_handler will process it. Otherwise,
355 * tttk_Xt_input_handler will just return.
357 tttk_Xt_input_handler( NULL, 0, 0 );
359 FileManagerToolTalkPattern = ttdt_session_join( tt_default_session( ),
364 if( tt_is_err( tt_ptr_error( FileManagerToolTalkPattern )))
366 ttdt_close( NULL, NULL, sendStopped );
372 ttdt_close( NULL, NULL, sendStopped );