File: actions.c

package info (click to toggle)
motif 2.3.8-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,432 kB
  • sloc: ansic: 452,643; sh: 4,613; makefile: 2,030; yacc: 1,604; lex: 352; cpp: 348
file content (175 lines) | stat: -rw-r--r-- 3,778 bytes parent folder | download | duplicates (4)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* $XConsortium: actions.c /main/5 1995/07/15 20:45:12 drk $ */
/*
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 * 
 */
/*
 * HISTORY
 */

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <pwd.h>
#include <Xm/Xm.h>           /* Motif Toolkit */
#include <Mrm/MrmPublic.h>   /* Mrm */
#include <Xm/Container.h>
#include <Xm/SelectioB.h>
#include <Xm/TextF.h>
#include "filemanager.h"

void 
gotoCB(Widget widget, XtPointer i1, XtPointer cb)
{
  Widget text;
  char *str;

  text = XtNameToWidget(widget, "*Text");

  str = XmTextFieldGetString(text);

  readdirCB(widget, str, NULL);

  XtFree(str);
}

void 
manageCB(Widget widget, Widget w_to_manage, XtPointer callback_data)
{
  if (w_to_manage != (Widget) NULL)
    XtManageChild(w_to_manage);
}

void 
viewCB(Widget widget, char   *type, XtPointer callback_data)
{
  XtEnum size=0, spatial=0;

  if (strcmp(type, "large") == 0) {
    size = XmLARGE_ICON;
    spatial = XmSPATIAL;
  } else if (strcmp(type, "small") == 0) {
    size = XmSMALL_ICON;
    spatial = XmSPATIAL;
  } else if (strcmp(type, "detail") == 0) {
    size = XmSMALL_ICON;
    spatial = XmDETAIL;
  }

  XtVaSetValues(fileviewer,
		XmNlayoutType, spatial,
		XmNentryViewType, size,
		0, NULL);

  fixViewerSize(XtParent(fileviewer), NULL, NULL);

  XmContainerRelayout(fileviewer);
}

void 
quitCB(Widget widget, char *tag, XmAnyCallbackStruct *callback_data)
{
  exit(0);
}

char* 
fullpath(char *filename)
{
  char buf[1024];
  char *rstr;

  /* This is for UNIX,  write something else for a non-UNIX OS */
  if (strcmp(currentdir, "/") == 0)
    sprintf(buf, "/%s", filename);
  else if (filename[0] == '/')
    sprintf(buf, "%s%s", currentdir, filename);
  else
    sprintf(buf, "%s/%s", currentdir, filename);

  rstr = XtNewString(buf);

  return(rstr);
}


void 
showHiddenCB(Widget widget, XtPointer ignore,
	     XmToggleButtonCallbackStruct *callback_data)
{
  showHidden = callback_data -> set;

  read_directory((Widget) NULL, ".");
}

void 
newFolder(Widget widget, XtPointer ignore, XtPointer ignore2)
{
  char buf[256];
  int i = 0;
  int status;
  Boolean done = False;
  struct stat statbuf;

  while(! done) {
    sprintf(buf, "%s/unnamed%d", currentdir, i);
    status = stat(buf, &statbuf);
    if (status != 0) {
      if (errno == ENOENT)
	done = True;
      else
	return; /* Bad error */
    }
    if (i >= 100) return;
    i++;
  }

  mkdir(buf, 0755);

}
     
void 
deleteItem(Widget widget, XtPointer ignore, XtPointer ignore2)
{
  WidgetList selected;
  Cardinal count;
  int i;

  /* First get list of selected items. */
  XtVaGetValues(fileviewer, 
		XmNselectedObjects, &selected,
		XmNselectedObjectCount, &count,
		NULL, NULL);

  if (count <= 0) return;
 
  for(i = 0; i < count; i++) {
    char buf[256];
    sprintf(buf, deleteCommand, getPathFromIcon(selected[i]));
    system(buf);
  }

  XtVaSetValues(fileviewer, XmNselectedObjectCount, 0, NULL, NULL);
}