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 librararies 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>
69 #include <X11/keysymdef.h>
71 #include <Dt/Session.h>
73 #include <Dt/Connect.h>
75 #include <Dt/Indicator.h>
77 #include <Dt/UserMsg.h>
80 #include <Dt/DtNlUtils.h>
81 #include <Dt/CommandM.h>
82 #include <Dt/EnvControlP.h>
87 #include "SharedProcs.h"
92 /* ToolTalk messages */
93 #define FM_TT_MSG_QUIT "Quit"
94 #define FM_TT_MSG_PAUSE "Pause"
95 #define FM_TT_MSG_RESUME "Resume"
96 #define FM_TT_MSG_GET_STAT "Get_Status"
97 #define FM_TT_MSG_DO_CMD "Do_Command"
100 #define VERSION "1.0"
102 static char* RESTRICTED_HEADER = "-restricted";
104 static Tt_pattern * FileManagerToolTalkPattern = NULL;
105 static Boolean sendStopped = False;
106 XtInputId ProcessToolTalkInputId = 0;
118 View *view = clientdata;
119 char local_host[MAXHOSTNAMELEN];
120 extern char home_host_name[];
124 DialogData *dialog_data;
132 to_file = tt_message_arg_val(msg, 1);
133 strcpy(local_host, home_host_name);
134 dialog_data = (DialogData *)view->dialog_data;
135 ShowNewDirectory( (FileMgrData *)dialog_data->data,
136 local_host, to_file);
138 /* Quit the old file, join the new */
139 ttdt_file_quit( view->pats, 0 );
140 view->pats = ttdt_file_join( to_file, TT_SESSION,
141 0, FileCallback, view );
142 if (tt_is_err( tt_ptr_error( view->pats ))) {
146 tttk_message_destroy( msg );
155 FinalizeToolTalkSession( )
160 for (i = 0; i < view_count; i++)
162 if (view_set[i]->msg != 0) {
163 if (view_set[i]->pats != 0) {
164 ttdt_file_quit( view_set[i]->pats, 0 );
165 view_set[i]->pats = 0;
167 tt_message_reply( view_set[i]->msg );
168 tttk_message_destroy( view_set[i]->msg );
169 view_set[i]->msg = 0;
173 if( FileManagerToolTalkPattern &&
174 tt_ptr_error( FileManagerToolTalkPattern ) == TT_OK )
176 ttRc = ttdt_session_quit( NULL,
177 FileManagerToolTalkPattern,
179 if( ProcessToolTalkInputId )
180 XtRemoveInput( ProcessToolTalkInputId );
182 ttRc = ttdt_close( NULL, NULL, sendStopped );
186 ToolTalkError( char * procName, Tt_status errId )
188 if( tt_is_err( errId ) )
193 XtRemoveInput( ProcessToolTalkInputId );
202 SessionCallback( Tt_message msg, void * client_data, Tt_message contract )
204 View *view = client_data;
205 char *opString = tt_message_op( msg );
206 Tttk_op op = tttk_string_op( opString );
215 tt_message_reply( msg );
216 FinalizeToolTalkSession( );
220 * Instead of quitting the whole process, we are to just
221 * quit the view associated with contract.
224 tttk_message_fail( msg, TT_DESKTOP_EINVAL, 0, 1 );
227 CloseView( (DialogData *)view->dialog_data );
228 tt_message_reply( msg );
229 tttk_message_destroy( msg );
236 MediaCallback( Tt_message msg,
240 unsigned char * contents,
246 Boolean restricted = False;
254 tttk_message_fail( msg, TT_DESKTOP_ENODATA, 0, 1 );
257 /* Buffers and files are the same to dtfile */
258 /* ToolTalk buffers are always null-terminated */
260 file = (char *)contents;
263 /* Old libtt SEGVs if you ask for a context that is not there */
264 if (tt_message_contexts_count( msg ) > 0) {
265 ceiling = tt_message_context_val( msg, "restricted" );
266 if (! tt_is_err( tt_ptr_error( ceiling ))) {
267 if ((ceiling == 0) || (strcmp( ceiling, "." ) != 0)) {
268 tttk_message_fail( msg,
269 TT_DESKTOP_ENOTSUP, 0, 1 );
281 * Create a display of the given directory tree
283 ViewDirectoryProc( file, restricted, msg );
288 tt_free( (caddr_t)contents );
293 InitializeToolTalkProcid( int *ttFd, Widget topLevel, Boolean sendStarted )
298 #ifdef DT_PERFORMANCE
299 printf(" InitializeToolTalkProcid\n");
300 gettimeofday(&update_time_s, NULL);
302 sendStopped = sendStarted;
303 procId = ttdt_open( ttFd,
309 #ifdef DT_PERFORMANCE
310 gettimeofday(&update_time_f, NULL);
311 if (update_time_s.tv_usec > update_time_f.tv_usec) {
312 update_time_f.tv_usec += 1000000;
313 update_time_f.tv_sec--;
315 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);
318 if( (ttstat = tt_ptr_error( procId )) == TT_OK )
320 ProcessToolTalkInputId =
321 XtAppAddInput( XtWidgetToApplicationContext( toplevel ),
322 *ttFd, (XtPointer)XtInputReadMask,
323 tttk_Xt_input_handler, procId );
328 ttdt_close( NULL, NULL, sendStopped );
335 InitializeToolTalkSession( Widget topLevel, int ttFd )
339 ttstat = ttmedia_ptype_declare( "DT_File_Manager",
345 ttstat = ttmedia_ptype_declare( "DT_File_Manager",
350 tt_ptype_opnum_callback_add( "DT_File_Manager", 0, HandleTtRequest );
354 * If we were started by a message, the following call to
355 * tttk_Xt_input_handler will process it. Otherwise,
356 * tttk_Xt_input_handler will just return.
358 tttk_Xt_input_handler( NULL, 0, 0 );
360 FileManagerToolTalkPattern = ttdt_session_join( tt_default_session( ),
365 if( tt_is_err( tt_ptr_error( FileManagerToolTalkPattern )))
367 ttdt_close( NULL, NULL, sendStopped );
373 ttdt_close( NULL, NULL, sendStopped );