Implement ActionList::Entry#clear.
[kaya.git] / lib / filewriter.rb
blob77eb939bf952ed377c90866c47a38a09ae810e7e
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 module FileWriter
9   def write_file(url, text)
10     return nil if url.is_empty
11     if url.is_local_file
12       File.open(url.path, 'w') do |f|
13         f.puts text
14       end
15     else
16       tmp_file = KDE::TemporaryFile.new
17       begin
18         return nil unless tmp_file.open
19         File.open(tmp_file.file_name, 'w') do |f|
20           f.puts text
21         end
22         return nil unless KIO::NetAccess.upload(tmp_file.file_name, url, self)
23       ensure
24         tmp_file.close
25       end
26     end
27     url
28   end
29 end