summaryrefslogtreecommitdiff
path: root/plugins/ImportTXT/importtxt.dpr
blob: 5cc6d128641035cb877fe000a65fe1b96d71bed3 (plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
(*
    ImportTXT plugin for Miranda IM: the free IM client for Microsoft* Windows*

    Copyright (Ñ) 2008 Abyss

    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; either version 2 of the License, or
    (at your option) any later version.

    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; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*)

{$IMAGEBASE $2080000}
library importtxt;

uses
  Windows,
  Messages,
  SysUtils,
  Inifiles,
  m_api,// in '.\inc\m_api.pas',
{ èñïîëüçóþòñÿ â ImportThrd
  KOL in '.\kol\kol.pas',
  err in '.\kol\err.pas',
  KOLedb in '.\kol\KOLEdb.pas',
}
  General in 'general.pas',
  ImportT in 'ImportT.pas',
  ImportTU in 'ImportTU.pas',
  ImportThrd in 'ImportThrd.pas',
  PerlRegEx in 'PerlRegEx.pas',
  ImportTxtDlg in 'ImportTxtDlg.pas',
  ImportTxtWiz in 'ImportTxtWiz.pas';

{$R imptxt_ver.res}

const MIID_IMPORTTEXT:TGUID = '{6F376B33-D3F4-4c4f-A96B-77DA08043B06}';

// Updater compatibility data
const
  VersionURL        = 'http://abyss.web.ur.ru/itxt_ver.htm';
  VersionPrefix     = 'Current version: ';
  UpdateURL         = 'http://abyss.web.ur.ru/importtxt.zip';
  BetaVersionURL    = nil;
  BetaVersionPrefix = nil;
  BetaUpdateURL     = nil;
  BetaChangelogURL  = nil;

var
  hwndWizard:HWND;
  hwndDialog:HWND;
  //Services
  SrvITxt,SrvIWiz:THANDLE;
  //hooks
  onLoadHook:THANDLE;
  onAccChangHook:THANDLE;

function MirandaPluginInfoEx(mirandaVersion:DWORD):PPLUGININFOEX; cdecl;
begin
  PluginInfo.cbSize     :=sizeof(TPLUGININFOEX);
  PluginInfo.shortName  :='Import TXT';
  PluginInfo.version    :=$0000010A;
  PluginInfo.description:='Imports history saved in TXT files from other clients.';
  PluginInfo.author     :='Abyss';
  PluginInfo.authorEmail:='abyss.andrey@gmail.com';
  PluginInfo.copyright  :='(C)2008 Abyss';
  PluginInfo.homepage   :='none';
  PluginInfo.flags      :=UNICODE_AWARE;
  PluginInfo.uuid       :=MIID_IMPORTTEXT;

  result := @PluginInfo;
end;

function ContactMenuCommand(wParam: wParam; lParam: lParam): int_ptr; cdecl;
begin
  result := 0;
  if IsWindow(hwndDialog) then
  begin
    SetForegroundWindow(hwndDialog);
    BringWindowToTop(hwndDialog);
  end
  else
    hwndDialog := CreateDialogParamW(hInstance, MAKEINTRESOURCEW(IDD_IMPDIALOG),
      0, @IDMainWndProc, wParam);
end;

function MainMenuCommand(wParam: wParam; lParam: lParam): int_ptr; cdecl;
begin
  result := 0;
  if (IsWindow(hwndWizard)) then
  begin
    SetForegroundWindow(hwndWizard);
    BringWindowToTop(hwndWizard);
  end
  else
    hwndWizard := CreateDialogW(hInstance, MAKEINTRESOURCEW(IDD_IMPWIZARD), 0, @WizardDlgProc);
end;

function OnAccountChanged(wParam: wParam; lParam: lParam): int; cdecl;
begin
  result := 0;
  EnumProtocols;
  if Assigned(OnAccountListChange) then
    OnAccountListChange;
end;

function OnModulesLoaded(wParam: wParam; lParam: lParam): int; cdecl;
var
  upd: TUpdate;
  buf: array [0 .. 63] of char;
begin
  UnhookEvent(onLoadHook);
  result := 0;
  EnumProtocols;
  // Register in updater
  if Boolean(ServiceExists(MS_UPDATE_REGISTER)) then
  begin
    ZeroMemory(@upd, sizeof(upd));
    upd.cpbVersion := sizeof(upd);
    upd.szComponentName := PluginInfo.shortName;;
    upd.pbVersion := CreateVersionStringPlugin(@PluginInfo, @buf);
    upd.cpbVersion := lstrlena(upd.pbVersion);
    upd.szUpdateURL := UpdateURL;
    upd.szVersionURL := VersionURL;
    upd.pbVersionPrefix := VersionPrefix;
    upd.cpbVersionPrefix := Length(VersionPrefix);
    upd.szBetaUpdateURL := BetaUpdateURL;
    upd.szBetaVersionURL := BetaVersionURL;
    upd.pbBetaVersionPrefix := BetaVersionPrefix;
    upd.cpbBetaVersionPrefix := Length(upd.pbBetaVersionPrefix);
    upd.szBetaChangelogURL := BetaChangelogURL;
    CallService(MS_UPDATE_REGISTER, 0, tlparam(@upd));
  end;
  // check for AutoStart
  if (DBReadByte(0, IMPORT_TXT_MODULE, IMPORT_TXT_AS) = 1) and (ProtoCount > 0) then
  begin
    CallService(IMPORT_WIZ_SERVICE, 0, 0);
    DBWriteByte(0, IMPORT_TXT_MODULE, IMPORT_TXT_AS, 0);
  end;
end;

function Load(): int; cdecl;
var
  mi: TCListMenuItem;
begin
  cp := CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
  SrvITxt := CreateServiceFunction(IMPORT_TXT_SERVICE, @ContactMenuCommand);
  SrvIWiz := CreateServiceFunction(IMPORT_WIZ_SERVICE, @MainMenuCommand);
  FillChar(mi, sizeof(mi), 0);
  mi.cbSize := sizeof(mi);
  mi.flags := 0;
  mi.position := 1000090050;
  mi.hIcon := LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DEFAULT));
  mi.szName.a := 'Import history';
  mi.pszService := IMPORT_TXT_SERVICE;
  mi.pszContactOwner := nil; // All contacts
  Menu_AddContacTMenuItem(@mi);

  mi.position := 500050010;
  mi.pszService := IMPORT_WIZ_SERVICE;
  mi.pszContactOwner := nil;
  Menu_AddMainMenuItem(@mi);

  onLoadHook := HookEvent(ME_SYSTEM_MODULESLOADED, @OnModulesLoaded);
  onAccChangHook := HookEvent(ME_PROTO_ACCLISTCHANGED, @OnAccountChanged);
  result := 0;
end;

function Unload: int; cdecl;
begin
  UnhookEvent(onAccChangHook);
  DestroyServiceFunction(SrvITxt);
  DestroyServiceFunction(SrvIWiz);
  Result := 0;
end;


exports

  Load, Unload,
  MirandaPluginInfoEx;

begin
end.