• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • kfile
kfile_kig.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Pino Toscano *
3  * toscano.pino@tiscali.it *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #include "kfile_kig.h"
22 
23 #include <qbytearray.h>
24 #include <qdom.h>
25 #include <qfile.h>
26 #include <qregexp.h>
27 
28 #include <karchive.h>
29 #include <kgenericfactory.h>
30 #include <kglobal.h>
31 #include <klocale.h>
32 #include <kstandarddirs.h>
33 #include <ktar.h>
34 
35 typedef KGenericFactory<KigPlugin> kigFactory;
36 
37 K_EXPORT_COMPONENT_FACTORY( kfile_kig, kigFactory( "kfile_kig" ) )
38 
39 KigPlugin::KigPlugin( QObject *parent, const QStringList &args )
40  : KFilePlugin( parent, args )
41 {
42  KFileMimeTypeInfo::ItemInfo* item;
43 
44  info = addMimeTypeInfo( "application/x-kig" );
45 
46  group = addGroupInfo( info, "KigInfo", i18n( "Summary" ) );
47  item = addItemInfo( group, "Version", i18n( "Version" ), QVariant::String );
48  item = addItemInfo( group, "CompatVersion", i18n( "Compatibility Version" ), QVariant::String );
49  item = addItemInfo( group, "CoordSystem", i18n( "Coordinate System" ), QVariant::String );
50  item = addItemInfo( group, "Grid", i18n( "Grid" ), QVariant::String );
51  item = addItemInfo( group, "Axes", i18n( "Axes" ), QVariant::String );
52  item = addItemInfo( group, "Compressed", i18n( "Compressed" ), QVariant::String );
53 }
54 
55 bool KigPlugin::readInfo( KFileMetaInfo& metainfo, uint /*what*/ )
56 {
57  KFileMetaInfoGroup metagroup = appendGroup( metainfo, "KigInfo");
58 
59  QString sfile = metainfo.path();
60  bool iscompressed = false;
61  QFile f( sfile );
62  if ( !sfile.endsWith( ".kig", Qt::CaseInsensitive ) )
63  {
64  iscompressed = true;
65 
66  QString tempdir = KGlobal::dirs()->saveLocation( "tmp" );
67  if ( tempdir.isEmpty() )
68  return false;
69 
70  QString tempname = sfile.section( '/', -1 );
71  if ( sfile.endsWith( ".kigz", Qt::CaseInsensitive ) )
72  {
73  tempname.remove( QRegExp( "\\.[Kk][Ii][Gg][Zz]$" ) );
74  }
75  else
76  return false;
77  // reading compressed file
78  KTar* ark = new KTar( sfile, "application/x-gzip" );
79  ark->open( QIODevice::ReadOnly );
80  const KArchiveDirectory* dir = ark->directory();
81  QStringList entries = dir->entries();
82  QStringList kigfiles = entries.filter( QRegExp( "\\.kig$" ) );
83  if ( kigfiles.count() != 1 )
84  return false;
85  const KArchiveEntry* kigz = dir->entry( kigfiles.at( 0 ) );
86  if ( !kigz->isFile() )
87  return false;
88  dynamic_cast<const KArchiveFile*>( kigz )->copyTo( tempdir );
89 
90  f.setFileName( tempdir + kigz->name() );
91  }
92 
93  if ( !f.open( QIODevice::ReadOnly ) )
94  return false;
95 
96  QDomDocument doc( "KigDocument" );
97  if ( !doc.setContent( &f ) )
98  return false;
99 
100  f.close();
101 
102  // removing temp file
103  if ( iscompressed )
104  f.remove();
105 
106  QDomElement main = doc.documentElement();
107 
108  // reading the version...
109  QString version = main.attribute( "Version" );
110  if ( version.isEmpty() ) version = main.attribute( "version" );
111  if ( version.isEmpty() ) version = i18nc( "Translators: Not Available", "n/a" );
112  appendItem( metagroup, "Version", version );
113 
114  // reading the compatibility version...
115  QString compatversion = main.attribute( "CompatibilityVersion" );
116  if ( compatversion.isEmpty() )
117  compatversion = i18nc( "%1 represents Kig version",
118  "%1 (as the version)", version );
119  appendItem( metagroup, "CompatVersion", compatversion );
120 
121  // reading the Coordinate System...
122  QByteArray coordsystem;
123  for ( QDomNode n = main.firstChild(); ! n.isNull(); n = n.nextSibling() )
124  {
125  QDomElement e = n.toElement();
126  if ( e.isNull() ) continue;
127  if ( e.tagName() == "CoordinateSystem" )
128  coordsystem = e.text().toLatin1();
129  }
130  appendItem( metagroup, "CoordSystem", coordsystem );
131 
132  // has Kig document the grid?
133  bool btmp = true;
134  QString stmp = main.attribute( "grid" );
135  if ( !( stmp.isEmpty() || ( stmp != "0" ) ) )
136  btmp = ( stmp != "0" );
137  QString stmp2 = btmp ? i18n( "Yes" ) : i18n( "No" );
138  appendItem( metagroup, "Grid", stmp2 );
139 
140  // has Kig document the axes?
141  btmp = true;
142  stmp = main.attribute( "axes" );
143  if ( !( stmp.isEmpty() || ( stmp != "0" ) ) )
144  btmp = ( stmp != "0" );
145  stmp2 = btmp ? i18n( "Yes" ) : i18n( "No" );
146  appendItem( metagroup, "Axes", stmp2 );
147 
148  stmp2 = iscompressed ? i18n( "Yes" ) : i18n( "No" );
149  appendItem( metagroup, "Compressed", stmp2 );
150 
151  return true;
152 }
153 
154 #include "kfile_kig.moc"
main
int main(int argc, char **argv)
Definition: main.cpp:97
KigPlugin
Definition: kfile_kig.h:28
KFilePlugin
kfile_kig.h
KigPlugin::readInfo
virtual bool readInfo(KFileMetaInfo &metainfo, uint what)
Definition: kfile_kig.cpp:55
kigFactory
KGenericFactory< KigPlugin > kigFactory
Definition: kfile_kig.cpp:35
uint
unsigned int uint
Definition: object_imp.h:87
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal