blob: 042fdea028c15b13cc4df88de174e44fd92f5a86 [file] [log] [blame]
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -05001/*
2 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
32package org.sflphone.account;
33
Alexandre Lision8ad39592013-11-21 13:23:58 -050034import org.sflphone.fragments.FileExplorerDFragment;
35import org.sflphone.fragments.FileExplorerDFragment.onFileSelectedListener;
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050036import org.sflphone.model.Account;
37
38import android.app.Activity;
Alexandre Lision8ad39592013-11-21 13:23:58 -050039import android.preference.CheckBoxPreference;
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050040import android.preference.EditTextPreference;
41import android.preference.Preference;
42import android.preference.Preference.OnPreferenceChangeListener;
43import android.preference.Preference.OnPreferenceClickListener;
44import android.preference.PreferenceScreen;
45import android.util.Log;
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050046
Alexandre Lision8ad39592013-11-21 13:23:58 -050047public class TLSManager implements onFileSelectedListener {
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050048 PreferenceScreen mScreen;
49 private Account mAccount;
50 static Activity mContext;
51
52 public void onCreate(Activity con, PreferenceScreen preferenceScreen, Account acc) {
53 mContext = con;
54 mScreen = preferenceScreen;
55 mAccount = acc;
56
57 setDetails();
58 }
59
60 private void setDetails() {
61 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
62
Alexandre Lision8ad39592013-11-21 13:23:58 -050063 if (mScreen.getPreference(i) instanceof CheckBoxPreference) {
64 ((CheckBoxPreference) mScreen.getPreference(i)).setChecked(mAccount.getTlsDetails().getDetailBoolean(
65 mScreen.getPreference(i).getKey()));
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050066 } else {
Alexandre Lision8ad39592013-11-21 13:23:58 -050067 mScreen.getPreference(i).setSummary(mAccount.getTlsDetails().getDetailString(mScreen.getPreference(i).getKey()));
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050068 }
69
70 // ((CheckBoxPreference)
71 // mScreen.getPreference(i)).setChecked(mAccount.getSrtpDetails().getDetailBoolean(mScreen.getPreference(i).getKey()));
72 mScreen.getPreference(i).setOnPreferenceClickListener(new OnPreferenceClickListener() {
73
74 @Override
75 public boolean onPreferenceClick(Preference preference) {
Alexandre Lision8ad39592013-11-21 13:23:58 -050076 if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE)
77 || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE)
78 || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) {
79 FileExplorerDFragment dialog = FileExplorerDFragment.newInstance();
80 dialog.show(mContext.getFragmentManager(), "explorerdialog");
81 dialog.setOnFileSelectedListener(TLSManager.this, preference.getKey());
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050082 }
Alexandre Lision8ad39592013-11-21 13:23:58 -050083
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -050084 return false;
85 }
86 });
87 }
88 }
89
90 public void setTLSListener() {
91 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
92 mScreen.getPreference(i).setOnPreferenceChangeListener(tlsListener);
93 }
94 }
95
96 private OnPreferenceChangeListener tlsListener = new OnPreferenceChangeListener() {
97
98 @Override
99 public boolean onPreferenceChange(Preference preference, Object newValue) {
100 Log.i("TLS", "Setting " + preference.getKey() + " to" + (Boolean) newValue);
101 mAccount.getTlsDetails().setDetailString(preference.getKey(), Boolean.toString((Boolean) newValue));
102 mAccount.notifyObservers();
103 return true;
104 }
105 };
106
Alexandre Lision8ad39592013-11-21 13:23:58 -0500107 @Override
108 public void onFileSelected(String path, String prefKey) {
109 mScreen.findPreference(prefKey).setSummary(path);
110 mAccount.getTlsDetails().setDetailString(prefKey, path);
111 mAccount.notifyObservers();
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -0500112 }
Alexandre Lision8ad39592013-11-21 13:23:58 -0500113
Alexandre Lisiondd5d8de2013-11-18 16:26:14 -0500114}