summaryrefslogtreecommitdiffstats
path: root/tdefile-plugins/txt
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-01-27 01:00:38 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-01-27 01:00:38 -0600
commit4bc3dcd8cbc23e1470e121e25a83d57c22e61b26 (patch)
tree7d379893635b06789888944241a976a4f2b440ab /tdefile-plugins/txt
parent08a66075486dc740840cfb817bf0ca301c6f0385 (diff)
downloadtdeaddons-4bc3dcd8cbc23e1470e121e25a83d57c22e61b26.tar.gz
tdeaddons-4bc3dcd8cbc23e1470e121e25a83d57c22e61b26.zip
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tdefile-plugins/txt')
-rw-r--r--tdefile-plugins/txt/Makefile.am21
-rw-r--r--tdefile-plugins/txt/tdefile_txt.cpp129
-rw-r--r--tdefile-plugins/txt/tdefile_txt.desktop70
-rw-r--r--tdefile-plugins/txt/tdefile_txt.h40
4 files changed, 260 insertions, 0 deletions
diff --git a/tdefile-plugins/txt/Makefile.am b/tdefile-plugins/txt/Makefile.am
new file mode 100644
index 0000000..71c0333
--- /dev/null
+++ b/tdefile-plugins/txt/Makefile.am
@@ -0,0 +1,21 @@
+## Makefile.am for text file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes)
+
+noinst_HEADERS = tdefile_txt.h
+
+kde_module_LTLIBRARIES = tdefile_txt.la
+
+tdefile_txt_la_SOURCES = tdefile_txt.cpp
+tdefile_txt_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+tdefile_txt_la_LIBADD = $(LIB_KIO)
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/tdefile_txt.pot
+
+services_DATA = tdefile_txt.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/tdefile-plugins/txt/tdefile_txt.cpp b/tdefile-plugins/txt/tdefile_txt.cpp
new file mode 100644
index 0000000..acf7a6d
--- /dev/null
+++ b/tdefile-plugins/txt/tdefile_txt.cpp
@@ -0,0 +1,129 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "tdefile_txt.h"
+
+#include <kgenericfactory.h>
+#include <kdebug.h>
+
+#include <tqfile.h>
+#include <tqstringlist.h>
+#include <tqregexp.h>
+
+typedef KGenericFactory<KTxtPlugin> TxtFactory;
+
+K_EXPORT_COMPONENT_FACTORY(tdefile_txt, TxtFactory("tdefile_txt"))
+
+KTxtPlugin::KTxtPlugin(TQObject *parent, const char *name,
+ const TQStringList &args) : KFilePlugin(parent, name, args)
+{
+ kdDebug(7034) << "Text file meta info plugin\n";
+ makeMimeTypeInfo( "text/plain" );
+}
+
+void KTxtPlugin::makeMimeTypeInfo(const TQString& mimeType)
+{
+ KFileMimeTypeInfo* info = addMimeTypeInfo(mimeType);
+
+ KFileMimeTypeInfo::GroupInfo* group =
+ addGroupInfo(info, "General", i18n("General"));
+
+ KFileMimeTypeInfo::ItemInfo* item;
+ item = addItemInfo(group, "Lines", i18n("Lines"), TQVariant::Int);
+ setAttributes(item, KFileMimeTypeInfo::Averaged);
+ item = addItemInfo(group, "Words", i18n("Words"), TQVariant::Int);
+ setAttributes(item, KFileMimeTypeInfo::Averaged);
+ item = addItemInfo(group, "Characters", i18n("Characters"), TQVariant::ULongLong);
+ setAttributes(item, KFileMimeTypeInfo::Averaged);
+ item = addItemInfo(group, "Format", i18n("Format"), TQVariant::String);
+}
+
+bool KTxtPlugin::readInfo(KFileMetaInfo& info, uint)
+{
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ TQFile f(info.path());
+ if (!f.open(IO_ReadOnly))
+ return false;
+
+ bool firstline = true;
+ int totLines = 0;
+ int totWords = 0;
+ unsigned long long totChars = f.size();
+ TQString fileFormat;
+ TQString line;
+ bool skipTotals = (totChars > 100*1024); // 100K is the max we read
+
+ unsigned int bytesRead = 0;
+ while (!f.atEnd())
+ {
+ f.readLine(line, 4096);
+
+ int len = line.length();
+
+ // The checks below are necessary to handle embedded NULLs
+ // TQFile::readLine() does not handle them well
+ bytesRead += len;
+ if (bytesRead > totChars)
+ break;
+ if (len == 0)
+ break;
+
+ if (firstline)
+ {
+ firstline = false;
+ if (line[len-1]=='\n')
+ {
+ if (len>=2 && line[len-2]=='\r')
+ fileFormat = i18n("DOS");
+ else
+ fileFormat = i18n("UNIX");
+ }
+ else if (line[len-1]=='\r')
+ fileFormat = i18n("Macintosh");
+ if (skipTotals)
+ break;
+ }
+
+ totWords += (TQStringList::split(TQRegExp("\\s+"), line)).count();
+ totLines++;
+ }
+
+ if (fileFormat.isEmpty())
+ fileFormat = i18n("Unknown");
+
+ kdDebug(7034) << "Lines: " << totLines << endl;
+ kdDebug(7034) << "Words: " << totWords << endl;
+ kdDebug(7034) << "Characters: " << totChars << endl;
+ kdDebug(7034) << "fileFormat: " << fileFormat << endl;
+
+ KFileMetaInfoGroup group = appendGroup(info, "General");
+ if (!skipTotals)
+ {
+ appendItem(group, "Lines", totLines);
+ appendItem(group, "Words", totWords);
+ }
+ appendItem(group, "Characters", totChars);
+ appendItem(group, "Format", fileFormat);
+
+ return true;
+}
+
+#include "tdefile_txt.moc"
diff --git a/tdefile-plugins/txt/tdefile_txt.desktop b/tdefile-plugins/txt/tdefile_txt.desktop
new file mode 100644
index 0000000..ab06d5f
--- /dev/null
+++ b/tdefile-plugins/txt/tdefile_txt.desktop
@@ -0,0 +1,70 @@
+[Desktop Entry]
+Type=Service
+Name=Text File Info
+Name[af]=Teks Lêer Inligting
+Name[ar]=معلومات ملف نصي
+Name[az]=Mətn Faylı Mə'lumatı
+Name[bg]=Информация за текстов файл
+Name[br]=Titouroù diwar-benn ar skrid restr
+Name[bs]=Info o tekst datoteci
+Name[ca]=Info. del fitxer de text
+Name[cs]=Info o textovém souboru
+Name[cy]=Gwybodaeth Ffeil Testun
+Name[da]=Information om tekstfil
+Name[de]=Informationen zur Textdatei
+Name[el]=Πληροφορίες αρχείου κειμένου
+Name[eo]=Tekstdosiera informo
+Name[es]=Información del archivo de texto
+Name[et]=Tekstifaili info
+Name[eu]=Testu fitxategiaren informazioa
+Name[fa]=اطلاعات پروندۀ متن
+Name[fi]=Tekstitiedoston tiedot
+Name[fo]=Tekstfíluupplýsingar
+Name[fr]=Informations sur le fichier texte
+Name[fy]=Teksttriem-ynfo
+Name[gl]=Información de Ficheiro de Texto
+Name[he]=מידע קובץ טקסט
+Name[hi]=पाठ फ़ाइल जानकारी
+Name[hr]=Podaci o tekstualnoj datoteci
+Name[hu]=Információ szöveges fájlokról
+Name[is]=Upplýsingar um textaskrá
+Name[it]=Informazioni File di testo
+Name[ja]=テキストファイル情報
+Name[ka]=ტექსტური ფაილის ინფორმაცია
+Name[kk]=Мәтін файлдың мәліметі
+Name[km]=ព័ត៌មាន​ឯកសារ​អត្ថបទ
+Name[lt]=Teksto bylos informacija
+Name[mk]=Информации за текстуална датотека
+Name[ms]=Maklumat Fail Teks
+Name[nb]=Tekstfilinformasjon
+Name[nds]=Textdatei-Informatschonen
+Name[ne]=पाठ फाइल सूचना
+Name[nl]=Tekstbestand-info
+Name[nn]=Informasjon om tekstfil
+Name[pa]=ਪਾਠ ਫਾਇਲ ਜਾਣਕਾਰੀ
+Name[pl]=Informacja o plikach tekstowych
+Name[pt]=Informações de Ficheiros de Texto
+Name[pt_BR]=Informações Sobre Arquivo texto
+Name[ro]=Informaţii fişier text
+Name[ru]=Информация о текстовом файле
+Name[sk]=Informácie o textovom súbore
+Name[sl]=Informacije o besedilni datoteki
+Name[sr]=Информације о текстуалном фајлу
+Name[sr@Latn]=Informacije o tekstualnom fajlu
+Name[sv]=Information om textfil
+Name[ta]=உரைக் கோப்பு தகவல்
+Name[tg]=Ахборот дар бораи файли матнӣ
+Name[th]=ข้อมูลแฟ้มข้อความ
+Name[tr]=Metin Dosyası Bilgisi
+Name[uk]=Інформація про текстовий файл
+Name[uz]=Matn fayli haqida maʼlumot
+Name[uz@cyrillic]=Матн файли ҳақида маълумот
+Name[vi]=Thông tin tập tin văn bản
+Name[xh]=Ulwazi Lombhalo Wefayile
+Name[zh_CN]=文本文件信息
+Name[zh_TW]=文字檔案資訊
+ServiceTypes=KFilePlugin
+X-TDE-Library=tdefile_txt
+MimeType=text/plain
+PreferredGroups=General
+PreferredItems=Lines,Words,Characters,Format
diff --git a/tdefile-plugins/txt/tdefile_txt.h b/tdefile-plugins/txt/tdefile_txt.h
new file mode 100644
index 0000000..86e80cc
--- /dev/null
+++ b/tdefile-plugins/txt/tdefile_txt.h
@@ -0,0 +1,40 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2002 Nadeem Hasan <nhasan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __KFILE_TXT_H_
+#define __KFILE_TXT_H_
+
+#include <tdefilemetainfo.h>
+
+class TQStringList;
+
+class KTxtPlugin: public KFilePlugin
+{
+ Q_OBJECT
+
+
+public:
+ KTxtPlugin(TQObject *parent, const char *name, const TQStringList& args);
+ virtual bool readInfo(KFileMetaInfo& info, uint what);
+
+private:
+ void makeMimeTypeInfo(const TQString& mimeType);
+};
+
+#endif