File: main.cpp

package info (click to toggle)
kdegraphics 2%3A980312-3
  • links: PTS
  • area: contrib
  • in suites: hamm
  • size: 6,168 kB
  • ctags: 5,778
  • sloc: ansic: 26,607; cpp: 21,205; sh: 5,224; makefile: 1,651; perl: 108
file content (144 lines) | stat: -rw-r--r-- 3,203 bytes parent folder | download
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
/****************************************************************************
**
** Copyright (C) 1997 by Mark Donohoe.
** Based on original work by Tim Theisen.
**
** This code is freely distributable under the GNU Public License.
**
*****************************************************************************/

#include <stdlib.h>
#include <stdio.h>

#include <qfiledlg.h>
#include <qmsgbox.h>
#include <klocale.h>
#include <kapp.h>
#include <kurl.h>

#include "kghostview.h"

Display *kde_display;

void Syntax(char *call)
{
	QString s( i18n( "Usage: " ) );
	s.append( call );
	s.append( i18n( " [filename] <siwtches>\n\n" ) );
	s.append( i18n( "See KDE and Qt documentation for\n"\
					"command line options.\n" ) );
	QMessageBox::warning( 0, i18n( "Command line error" ), s );
}

class MyApp : public KApplication
{
public:

  	MyApp( int &argc, char **argv, const QString &rAppName );
 	virtual bool x11EventFilter( XEvent * );
	~MyApp();
};

MyApp::MyApp( int &argc, char **argv, const QString &rAppName )
			: KApplication( argc, argv, rAppName )
{
}

MyApp::~MyApp()
{
	//printf("MyApp::~MyApp()\n");
}

bool MyApp::x11EventFilter( XEvent *ev ) {
	
	for ( KGhostview *kg = KGhostview::windowList.first(); kg!=0;
		kg=KGhostview::windowList.next() )
	{ 
	
	if(ev->xany.type == ClientMessage) {
		kg->page->mwin = ev->xclient.data.l[0];
		//fprintf(stderr, 
		//	"kghostview: Ghostscript communication window set as 0x%lx\n",
		//	kg->page->mwin);
		
		XClientMessageEvent *cme = ( XClientMessageEvent * ) ev;
		
		if(cme->message_type == kg->page->gs_page) {
			kg->page->busy=False;
			kg->page->fullView->setCursor( arrowCursor );
			return TRUE;
			
		} else if(cme->message_type == kg->page->done) {
			kg->page->disableInterpreter();
			return TRUE;
			
		}
	}
	}
	
	if ( KApplication::x11EventFilter( ev ) )
		return TRUE;
	else
		return FALSE;	
}

int main( int argc, char **argv )
{
	MyApp a( argc, argv, "kghostview" );
	
	signal( SIGCHLD, SIG_DFL );
	
	struct stat sbuf;
	
	KGhostview::windowList.setAutoDelete( FALSE );
	
	if (argc > 2) Syntax(argv[0]);
	
	if ( a.isRestored() ) {
		int n = 1;
		while (KTopLevelWidget::canBeRestored(n)) {
	    	KGhostview *kg = new KGhostview ();
			CHECK_PTR( kg );
		}
    } else if (argc == 2) {
	
		KGhostview *kg = new KGhostview ();
		CHECK_PTR( kg );
	
		kg->filename = argv[1];
		if (strcmp(kg->filename, "-")) {
		        KURL u( kg->filename );
			if ( strcmp( u.protocol(), "file" ) != 0 || u.hasSubProtocol() )
			{
			    kg->openNetFile( kg->filename );
			}
			else
			{
			    if ( ( kg->psfile = fopen( argv[1], "r") ) == 0 ) {
					QString s;
					s.sprintf( i18n("The document named\n%s\n"\
							"could not be opened.\n"\
							"No document has been loaded.\n\nError: %s" ),
						   argv[1], strerror(errno) );

					/* Stephan: this is highly unportable 
					   if (errno <= sys_nerr) {
					   s.append( "Error:\n" );
					   s.append( sys_errlist[errno] );
					   }	   
					*/

 					QMessageBox::warning(0, i18n("Open file error"), s );
			    }
			    stat(kg->filename, &sbuf);
			    kg->mtime = sbuf.st_mtime;
			}
		}
	} else {
		KGhostview *kg = new KGhostview ();
		CHECK_PTR( kg );
	}
	
	return a.exec();
}