OSDN Git Service

LinuxでDnDにより書庫にファイルを追加しようとした場合に、誤って書庫を作成する操作を実行していたバグを修正。
[tpi/lychee.git] / src / lychee / cls_filedroptarget.cpp
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \r
5   This library is free software; you can redistribute it and/or modify it under\r
6   the terms of the GNU Lesser General Public License as published by the Free\r
7   Software Foundation; either version 2.1 of the License, or (at your option)\r
8   any later version.\r
9 \r
10   This library is distributed in the hope that it will be useful, but WITHOUT\r
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License\r
13   for more details.\r
14 \r
15   You should have received a copy of the GNU Lesser General Public License along\r
16   with this library; if not, write to the Free Software Foundation, Inc.,\r
17   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
18 \r
19   $Id$\r
20 *******************************************************************************/\r
21 \r
22 #include "lychee.h"\r
23 \r
24 #include "frm_main.h"\r
25 #include "cls_filedroptarget.h"\r
26 \r
27 //******************************************************************************\r
28 // myFileDropTarget\r
29 //******************************************************************************\r
30 \r
31 myFileDropTarget::myFileDropTarget(MainFrame * mainFrame)\r
32 {\r
33         this->mainFrame = mainFrame;\r
34 }\r
35 \r
36 //******************************************************************************\r
37 // Event handler.\r
38 //******************************************************************************\r
39 \r
40 bool myFileDropTarget::OnDropFiles(wxCoord, wxCoord, const wxArrayString & asFiles)\r
41 {\r
42         wxCommandEvent * e;\r
43         this->as = asFiles;\r
44         if (::wxGetKeyState(WXK_SHIFT) && this->mainFrame->aiArchive.fiInfo.eSupportedCommand & TPI_COMMAND_ADD)\r
45         {\r
46                 // 書庫へ追加。\r
47                 e = new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("Arc_Add"));\r
48                 e->SetClientData(& this->as);\r
49                 e->SetInt(2);\r
50 #if wxCHECK_VERSION(2, 9, 0)\r
51                 this->mainFrame->GetEventHandler()->QueueEvent(e);\r
52 #else\r
53                 this->mainFrame->OnArcAdd(* e);\r
54                 delete e;\r
55 #endif\r
56                 return true;\r
57         }\r
58 \r
59         // ファイルが存在するか確認。\r
60         if (asFiles.GetCount() == 1 && ::wxFileExists(asFiles[0]))\r
61         {\r
62                 // 書庫を開く。\r
63                 e = new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("Arc_Open"));\r
64                 e->SetClientData(& this->as);\r
65                 e->SetInt(2);\r
66                 this->mainFrame->fnArchive = wxFileName(asFiles[0]);\r
67 #if wxCHECK_VERSION(2, 9, 0)\r
68                 this->mainFrame->GetEventHandler()->QueueEvent(e);\r
69 #else\r
70                 this->mainFrame->OnArcOpen(* e);\r
71                 delete e;\r
72 #endif\r
73                 return true;\r
74         }\r
75 \r
76         // 対応していない場合は書庫の作成を試みる。\r
77         e = new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("Arc_Create"));\r
78         e->SetClientData(& this->as);\r
79 #if wxCHECK_VERSION(2, 9, 0)\r
80         this->mainFrame->GetEventHandler()->QueueEvent(e);\r
81 #else\r
82         this->mainFrame->OnArcCreate(* e);\r
83         delete e;\r
84 #endif\r
85         return true;\r
86 }\r
87 \r
88 //******************************************************************************\r
89 // myFileDataObject\r
90 //******************************************************************************\r
91 \r
92 myFileDataObject::~myFileDataObject()\r
93 {\r
94         // ファイルを削除。\r
95         for (size_t i = 0; i < this->m_filenames.GetCount(); i++)\r
96         {\r
97                 chmod(this->m_filenames[i].ToUTF8(), 0600);\r
98                 ::wxRemoveFile(this->m_filenames[i]);\r
99         }\r
100 \r
101         // 一時ディレクトリを削除。\r
102         ::wxRmdir(this->szTempDir);\r
103 }\r
104 \r
105 #ifdef __LINUX__\r
106 // wxGTKのwxFileDataObjectでは多バイト文字の扱いに問題があるので代替。\r
107 bool myFileDataObject::GetDataHere(void * buf) const\r
108 {\r
109         wxString filenames;\r
110         for (size_t i = 0; i < m_filenames.GetCount(); i++)\r
111         {\r
112                 filenames += wxT("file:") + m_filenames[i] + wxT("\r\n");\r
113         }\r
114         memcpy(buf, filenames.mbc_str(), strlen(filenames.mbc_str()) + 1);\r
115         return true;\r
116 }\r
117 \r
118 size_t myFileDataObject::GetDataSize() const\r
119 {\r
120         size_t res = 1;\r
121         for (size_t i = 0; i < m_filenames.GetCount(); i++)\r
122         {\r
123                 res += strlen(m_filenames[i].mbc_str()) + 5 + 2; // "file:" (5) + "\r\n" (2)\r
124         }\r
125         return res;\r
126 }\r
127 \r
128 void myFileDataObject::AddFile(const wxString & filename)\r
129 {\r
130         m_filenames.Add(filename);\r
131 }\r
132 #endif\r